这个问题与提到的不重复
迁移未正确运行:////
Schema::create('player_password_reset_links', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('player_id');
$table->string('token');
$table->timestamp('created_at');
$table->timestamp('expires_at');
$table->timestamp('used_at')->nullable();
$table
->foreign('player_id')
->references('id')
->on('players');
});
我明白了
SQLSTATE[42000]:语法错误或访问冲突:1067 无效 “expires_at”的默认值(SQL:创建表 `player_password_reset_links` (`id` bigint unsigned not null auto_increment主键,`player_id`bigint unsigned not null, `token` varchar(255) 不为空,`created_at` 时间戳不为空, `expires_at` 时间戳不为空,`used_at` 时间戳为空)默认 字符集 utf8mb4 整理 'utf8mb4_unicode_ci')
我试过这样做之后
DB::statement('alter table player_password_reset_links add expires_at timestamp not null after created_at;');
但这会导致
SQLSTATE[42000]:语法错误或访问冲突:1067 无效 “expires_at”的默认值(SQL:alter table player_password_reset_links 添加 expires_at 时间戳后不为空 创建于;)
如果我在 MySQL 中运行这个查询,那就没问题,Laravel 做了什么不同的事情?
Laravel 时间戳列要求您将它们定义为可为空或具有默认值。
因此您必须将其设置为:
$table->timestamp('expires_at')->nullable();
或
$table->timestamp('expires_at')->useCurrent();
对于具有标准名称(如
created_at/created
和 updated_at/updated
)的列来说,这不是必需的