When i specify a function name as a table column default, this is wrapped into quotes so when executed the function isn't run, its saved as a string.
This gives an error fortunately because UUID col can't have a default string value of this type.
Schema::create('products', function(Blueprint $table)
{
$table->uuid('id')->default('gen_random_uuid()')->primary('products_pkey');
$table->string('name')->nullable();
$table->string('max_projects')->nullable();
$table->timestamps();
$table->softDeletes();
});
Try with DB::raw
:
$table->uuid('id')->default(DB::raw('gen_random_uuid()'))->primary('products_pkey');
You can't use a function as a default value in MySQL. It has to be a constant. To generate a UUID, you'd have to either use a trigger or do it manually.
gen_random_uuid()
is a Postgre function.
Most helpful comment
Try with
DB::raw
: