-
Notifications
You must be signed in to change notification settings - Fork 11.8k
Having issue with not null keywork while using ->virtualAs #16643
Copy link
Copy link
Closed
Labels
Description
- Laravel Version: 5.3.26
- PHP Version: 5.6
- Database Driver & Version: MariaDB (10.1.13-MariaDB)
Description:
Got syntax error using MariaDB version 10.1.13
('not null, created_at timestamp)
I think when adding virtual column not null will be not as virtual generated column can't be nulled.
I used --prepend method and removed not null keyword and query get accepted.
Steps To Reproduce:
make migration using following query:
Schema::create('orders', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id');
$table->text('details')->nullable();
$table->enum('status',['NEW','COMPLETED','PENDING','INPROGRESS','CANCELLED'])->default('NEW');
$table->decimal('gross_amount',5,2)->default(0);
$table->float('discount_percentage',3,2)->default(0);
$table->decimal('discount_amount',5,2)->default(0);
$table->decimal('net_amount',5,2)->virtualAs('gross_amount - discount_amount'); //error here
$table->timestamps();
});
My Workaround (author may have better way):
/**
* Get the SQL for a nullable column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @return string|null
*/
protected function modifyNullable(Blueprint $blueprint, Fluent $column)
{
if (! is_null($column->virtualAs))
return;
return $column->nullable ? ' null' : ' not null';
}
@ /vendor/laravel/framework/src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Type
Fields
Give feedbackNo fields configured for issues without a type.