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?

《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 2
leo

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

6年前 评论

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

6年前 评论

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