Heroku 环境中 timestamps () 无法自动维护 created_at 和 update_at 字段?
如题, 我在本地的环境下可以维护 created_at
和 update_at
这两个字段,但是在 Heroku 环境中去无法维护
迁移代码如下:
public function up()
{
Schema::create('followers', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->index();
$table->integer('follower_id')->index();
$table->timestamps();
});
}
在 Heroku 环境中执行 insert 动作的时候似乎没有自动去维护 created_at
和 update_at
这两个字段,如下
>>> $user=App\Models\User::find(1)
=> App\Models\User {#722
id: 1,
name: "Yang",
email: "******@qq.com",
created_at: "2017-06-17 11:11:15",
updated_at: "2017-06-17 11:13:18",
is_admin: false,
activation_token: null,
activated: true,
}
>>> $user->followings()->getRelatedIds()->toArray()
=> []
>>> $user->followings()->sync([2],false)
Illuminate\Database\QueryException with message 'SQLSTATE[23502]: Not null violation: 7 ERROR: null value in column "created_at" violates not-null constraint
DETAIL: Failing row contains (6, 2, 1, null, null). (SQL: insert into "followers" ("follower_id", "user_id") values (1, 2))'
Why?
定义followers relation的时候要加上
->withTimestamps()
@leo 十分感谢,确实是我漏掉了
->withTimestamps()
。但是还有一个疑问,为什么在本地中不使用->withTimestamps()
却不报错,而在 Heroku 中不使用->withTimestamps()
却报错呢?