Make column not nullable in a Laravel migration

bilalq picture bilalq · Dec 23, 2012 · Viewed 79.7k times · Source

I'm writing a migration to make certain columns in a table nullable right now. For the down function, I of course want to make those columns not nullable again. I looked through the schema builder docs, but couldn't see a way to do this.

Any help would be appreciated.

Answer

TLGreg picture TLGreg · Dec 24, 2012

Prior to Laravel 5 there was no Laravel native way of altering an existing table column using the schema builder. You'd need to use raw queries for this.

However, as of Laravel 5 you can use:

$table->...->nullable(false)->change();