Set default to NULL with laravel migration

Laravel

Laravel Problem Overview


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 NULLin 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);
});

Laravel Solutions


Solution 1 - Laravel

When you use the nullable() method on a field, that field will default to NULL.

$table->integer('parent_item_category_id')->nullable();

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJames StottView Question on Stackoverflow
Solution 1 - LaravelJames StottView Answer on Stackoverflow