我用unsigned user_id创建了一个迁移。我如何编辑user_id在一个新的迁移,也使它为空()?
Schema::create('throttle', function(Blueprint $table)
{
$table->increments('id');
// this needs to also be nullable, how should the next migration be?
$table->integer('user_id')->unsigned();
}
对于Laravel 4.2, Unnawut的答案是最好的。但如果使用表前缀,则需要稍微更改代码。
function up()
{
$table_prefix = DB::getTablePrefix();
DB::statement('ALTER TABLE `' . $table_prefix . 'throttle` MODIFY `user_id` INTEGER UNSIGNED NULL;');
}
为了确保您仍然可以回滚迁移,我们还将执行down()。
function down()
{
$table_prefix = DB::getTablePrefix();
DB::statement('ALTER TABLE `' . $table_prefix . 'throttle` MODIFY `user_id` INTEGER UNSIGNED NOT NULL;');
}