I am adding a field to a table in a migration that I wish to allow to be NULL but also I wish for it to default to NULL. What do I place in the default method? I fear that putting "NULL"
in will attempt to place a string of NULL
in which I obviously don't want. Please help :)
Schema::table('item_categories', function(Blueprint $table) { $table->integer('parent_item_category_id')->unsigned()->nullable()->default($what_to_put here); });
In our case we are going to do second option - create new migration. If we roll back this migration, we need to remove default value from that field using migration and this is how to do it: Schema::table('photos', function (Blueprint $table) { $table->integer('order')->default(NULL)->change(); });
The code to change the column to nullable is as "nullable()->change()". ->nullable()->change();
This is how you do it, I have checked it and it works on my Laravel 4.2. $table->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP')); Hope this helps.
When you use the nullable()
method on a field, that field will default to NULL.
$table->integer('parent_item_category_id')->nullable();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With