Reputation: 12927
Here's some sample code:
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('orders', function(Blueprint $table)
{
$table->integer('user_id')->unsigned()->nullable()->change();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('orders', function(Blueprint $table)
{
$table->integer('user_id')->unsigned()->change();
});
}
The first part works great. Basically, I'm taking an existing user_id column and altering it so that it's nullable. Works perfectly.
However, when I run migrate:rollback, the column stays nullable and I have an imperfect up/down migration relationship. What's the best practice solution for resolving this?
Upvotes: 1
Views: 127
Reputation: 5781
The only way I would suggest doing this is to run the DB::statement()
method. Something like the following
public function down() {
DB::statement('ALTER TABLE `orders` MODIFY `user_id` INTEGER UNSIGNED NOT NULL;');
}
Upvotes: 2