Laravel - SQLSTATE[42000]:语法错误或访问冲突:1067 无效的默认值

Laravel - SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value

我正在创建一个带有 2 个时间戳的迁移,但由于某些原因我不能在没有 default/nullable 值的情况下放置 2 timestamps

我的代码:

        Schema::create('lessons', function (Blueprint $table) {
            $table->id();
            $table->timestamp('checkin');
            $table->timestamp('checkout');
            $table->string('url')->nullable();
            $table->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP'));
            $table->timestamp('updated_at')->default(DB::raw('CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP'));
            $table->softDeletes();
        });

如果我在 checkout 中放置一个可为 null 的值:$table->timestamp('checkout')->nullable; 我的代码工作正常。但是我的两个值不能为空。

错误:

 Illuminate\Database\QueryException 

  SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'checkout' (SQL: create table `lessons` (`id` bigint unsigned not null auto_increment primary key, `checkin` timestamp not null, `checkout` timestamp not null, `url` varchar(191) null, `created_at` timestamp not null default CURRENT_TIMESTAMP, `updated_at` timestamp not null default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, `deleted_at` timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

如果更改顺序,bug 发生与签入相同

SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'checkin' (SQL: create table `lessons` (`id` bigint unsigned not null auto_increment primary key, `checkout` timestamp not null, `checkin` timestamp not null, `url` varchar(191) null, `created_at` timestamp not null default CURRENT_TIMESTAMP, `updated_at` timestamp not null default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, `deleted_at` timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

我认为这可能是 Laravel 中的一个错误。

我用这个 post 解决了我的问题:

我已将 timestamp 更改为 dateTime