here is my migration script
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();
});
i have to create generated-columns for total and due columns.
but while i tried to run the migration file its showing exception
Exception:
Illuminate\Database\QueryException : SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'stored,
paid
decimal(8, 2 ) not null default '0',due
decimal(8, 2) as (total' at line 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'
)
Note: i have mysql Ver 15.1 Distrib 10.1.35-MariaDB, for Win32
what i missed ?