我如何使 Laravel 迁移更改并使列可以为空

Fay*_*med 2 database-design laravel

我创建了一个 post_id 未签名的迁移。如何在新迁移中编辑 post_id 以使其也成功nullable()?

    Schema::create('throttle', function(Blueprint $table)
    {
        $table->increments('id');
        $table->integer('post_id')->unsigned(); // this needs to also be nullable, how should the next migration be?
    }
Run Code Online (Sandbox Code Playgroud)

Tru*_*ang 7

创建 migrate 并添加您的 up 函数,如下所示:

$table->integer('post_id')->nullable()->change();
Run Code Online (Sandbox Code Playgroud)