Heroku 环境中 timestamps () 无法自动维护 created_at 和 update_at 字段?

如题, 我在本地的环境下可以维护 created_atupdate_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_atupdate_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?

《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 2
leo

定义followers relation的时候要加上->withTimestamps()

7年前 评论

@leo 十分感谢,确实是我漏掉了 ->withTimestamps() 。但是还有一个疑问,为什么在本地中不使用 ->withTimestamps()却不报错,而在 Heroku 中不使用 ->withTimestamps()却报错呢?

7年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!