0
我使用遷移將nullable()添加到列。數據庫遷移notnull()?
class ChangeUgIdCanNull extends Migration
{
public function up()
{
Schema::table('service_request_step', function (Blueprint $table) {
$table->dropForeign(['ug_id']);
});
Schema::table('service_request_step', function (Blueprint $table) {
$table->dropIndex(['ug_id']);
});
Schema::table('service_request_step', function (Blueprint $table) {
$table->integer('ug_id')->unsigned()->index()->nullable()->change();
$table->foreign('ug_id')->references('ug_id')
->on('user_group')->onDelete('cascade');
});
}
public function down()
{
Schema::table('service_request_step', function (Blueprint $table) {
$table->dropForeign(['ug_id']);
});
Schema::table('service_request_step', function (Blueprint $table) {
$table->dropIndex(['ug_id']);
});
Schema::table('service_request_step', function (Blueprint $table) {
$table->integer('ug_id')->unsigned()->index()->change();
$table->foreign('ug_id')->references('ug_id')
->on('user_group')->onDelete('cascade');
});
}
}
當我使用php artisan migrate
是好的。 但是,當我想要php artisan migrate:rollback.
在我的'ug_id'列中的數據庫仍然可以爲空。 難道我有一個像$table->integer('ug_id')->unsigned()->index()->notnull()->change();
Laravel Version: 5.4.19
PHP Version: 7.1.3
Database Driver & Version: 10.2.4-MariaDB
Wowww。那是。謝謝。 – ThunderBirdsX3