【发布时间】:2018-10-13 20:30:55
【问题描述】:
这是我的迁移架构:
public function up()
{
Schema::create('objects', function (Blueprint $table) {
$table->increments('id');
$table->timestamp('timestamp1');
$table->timestamp('timestamp2');
});
}
但是当我执行php artisan migrate 时,我得到了这个错误:
Illuminate\Database\QueryException : SQLSTATE[42000]: 语法错误或访问冲突:1067 'timestamp2' 的默认值无效 (SQL: create table
objects(idint unsigned not null auto_increment 主键,timestamp1timestamp not null,timestamp2timestamp not null) 默认字符集 utf8mb4 collate utf8mb4_unicode_ci)
我必须指出,当我删除 2 个 $table->timestamp(...); 行之一时,它可以工作,但当两者都存在时,它就不行了。 Object.php 模型是空的。我是不是搞错了?
我已经阅读了this post,但是即使我将timestamp(...) 更改为dateTime(...) 时不再出现错误,我只想要时间戳。
【问题讨论】:
-
create 语句对我来说很好用。你用的是什么版本的mysql?
-
一张表中只有一个时间戳列,所以将其设为CHAR更新该列的数据类型。
标签: php laravel eloquent sql-timestamp