我在 Laravel 6.6 中创建了一个具有以下定义的表。
public function up()
{
Schema::create('quarters', function (Blueprint $table) {
$table->integer('quarter_id')->unsigned();
$table->integer('year')->unsigned();
$table->integer('quarter_num')->unsigned();
$table->timestamp('valid_from');
$table->timestamp('valid_to'); // <------ error on this line
$table->string('description')->nullable();
$table->timestamps();
$table->primary('quarter_id');
});
}
当我运行迁移命令时,出现以下错误。
Illuminate\Database\QueryException:SQLSTATE[42000]:语法错误或访问冲突:1067“valid_to”的默认值无效(SQL:创建表quarters(quarter_idint unsigned not null,year int unsigned not null,quarter_numint unsigned not null,valid_fromtimestamp not null,valid_totimestamp not null, description varchar(255) null, created_attimestamp null, updated_attimestamp null) 默认字符集 utf8mb4 collate 'utf8mb4_unicode_ci')
这是 Eloquent 生成的 SQL:
CREATE TABLE `quarters`(
`quarter_id` INT UNSIGNED NOT NULL,
`year` INT UNSIGNED NOT NULL,
`quarter_num` INT UNSIGNED NOT NULL,
`valid_from` TIMESTAMP NOT NULL,
`valid_to` TIMESTAMP NOT NULL,
`description` VARCHAR(255) NULL,
`created_at` TIMESTAMP NULL,
`updated_at` TIMESTAMP NULL
) DEFAULT CHARACTER SET utf8mb4 COLLATE 'utf8mb4_unicode_ci'
奇怪的是,如果我注释掉该valid_to行,那么它会创建没有错误的表。但是 的定义与valid_to100% 相似valid_from,并且它不会为valid_from列抛出该错误。实际上,数据库似乎不允许两timestamp列!
慕田峪9158850
猛跑小猪