【发布时间】:2016-01-07 05:36:18
【问题描述】:
我发现这个问题与我的 Make column not nullable in a Laravel migration 非常相似,尽管它已经快 3 年了,而且它肯定不属于 Laravel 5
我的问题是我有一个迁移,它在up 函数中修改了一个列以使其可以为空。
现在,在down 函数中,我想让它不再可以为空。
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('mytable', function(Blueprint $table) {
$table->string('mycolumn')->nullable()->change();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('mytable', function(Blueprint $table) {
/* THIS IS WHAT I WOULD EXPECT TO DO
THOUGH OF COURSE THE FUNCTION notNullable DOES NOT WORK */
$table->string('mycolumn')->notNullable()->change();
});
}
我可以使用原始 SQL 来实现,但如果可能的话,我想使用 Laravel 方法来实现......但我找不到它,可能它还没有在版本 5 中实现。
【问题讨论】:
-
从我在源代码中可以看到,
nullable()没有对立面,因此您可能需要使用 Db 门面进行原始查询。 -
谢谢@Amo,恐怕你是对的。