如何解决Laravel 7-奇怪的时间戳迁移行为
我正在通过迁移文件创建表。
我有多个时间戳列,其中之一不应为空。
如果我先设置该列以使迁移顺利进行,那么如果我在其前面放置了任何可空的时间戳列,则迁移将失败,并出现以下异常:
SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'credit_date' (SQL: create table `feedback_survey_records` (`id` bigint unsigned not null auto_increment primary key,`user_id` bigint unsigned not null,`feedback_survey_id` bigint unsigned not null,`reward` smallint not null,`credit_status` varchar(45) null,`answer_date` timestamp null,`open_date` timestamp null,`credit_date` timestamp not null,`decline_date` timestamp null,`decline_reason` varchar(255) null,`response_id` varchar(255) null,`created_at` timestamp null,`updated_at` timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci' engine = innodb)
成功迁移
$table->timestamp('credit_date');
$table->timestamp('answer_date')->nullable();
$table->timestamp('open_date')->nullable();
$table->timestamp('decline_date')->nullable();
迁移失败
$table->timestamp('answer_date')->nullable();
$table->timestamp('open_date')->nullable();
$table->timestamp('credit_date');
$table->timestamp('decline_date')->nullable();
我查看了数据库,发现laravel为成功迁移自动添加了默认值和额外的说明 Database structure Image
有人可以说明为什么会发生这种情况吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。