storedAs()在Laravel中生成的列(MySQL)中的错误

时间:2018-12-13 05:26:53

标签: php laravel migration mariadb

这是我的迁移脚本

Schema::create('orders', function (Blueprint $table) {
            .
            .
            .
            $table->decimal('coupon_discount')->default(0);
            $table->decimal('delivery_charge')->default(0);
            $table->decimal('sub_total')->default(0);
            $table->decimal('total')->storedAs('(sub_total + delivery_charge) - coupon_discount');
            $table->decimal('paid')->default(0);
            $table->decimal('due')->storedAs('total - paid');
            $table->longText('note')->nullable();
            .
            .
            .
            $table->timestamps();
        });

我必须为总数列和到期列创建generated-columns

但是当我尝试运行迁移文件时,它显示异常

例外:

  

Illuminate \ Database \ QueryException:SQLSTATE [42000]:语法错误   或访问冲突:1064您的SQL语法有错误;校验   与您的MariaDB服务器版本相对应的手册   在'stored,paid十进制(8,2)附近使用正确的语法,不为null   默认值'0',due十进制(8,2)为(总计)第1行(SQL:

create table orders (
    id int unsigned not null auto_increment primary key, 
    user_id int unsigned null, 
    area_id int unsigned not null, 
    location_id int unsigned not null, 
    delivery_add ress longtext not null, 
    delivery_address_id int unsigned null, 
    mobile varchar(191) not null, 
    email varchar(191) null, 
    coupon_id int unsigned null, 
    coupon_discount decimal(8, 2) not null default '0', 
    delivery_charge decimal(8, 2) not null default '0 ', 
    sub_total decimal(8, 2) not null default '0', 
    total decimal(8, 
    2) as ((sub_total + delivery_charge) - coupon_discount) stored, 
    paid decimal(8, 2) not null default '0', 
    due decimal(8, 
    2) as (total - paid) stored, 
    note longtext null, 
    order_type tin yint not null, 
    delivery_type tinyint not null, 
    status smallint not null default '0', 
    payment_method tinyint not null, 
    payment_channel smallint null, 
    payment_status tinyint not null default '0', 
    created_at timestamp null, 
    updated_at timestamp null
) default character set utf8mb4 collate 'utf8mb4_unicode_ci'
)

注意:我有 mysql Ver 15.1 Distrib 10.1.35-MariaDB,用于Win32

我错过了什么?

1 个答案:

答案 0 :(得分:0)

[已解决]

这是我的MariaDB版本问题,而不是PHP

将MariaDB 10.1升级到10.3。现在工作正常。

遵循了here

的解决方案

感谢乔纳斯,萨钦,蒂姆