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 (将#修改为@)