Laravel Migrations - Issues while creating timestamps

后端 未结 10 581
深忆病人
深忆病人 2021-02-05 15:35

I am trying to run migrations on my Laravel instance. They are just the default migrations (users and password resets) but when it tries to make the timestamps it throws this e

相关标签:
10条回答
  • 2021-02-05 16:32

    MySQL 5.7.28

    The MySQL docs recommend the following (note the use of GLOBAL):

    SET GLOBAL sql_mode = 'ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
    
    0 讨论(0)
  • 2021-02-05 16:34

    it sounds like strict mode.

    You may disable strict mode in one of two ways:

    Open your my.ini file within the MySQL installation directory, and look for the text sql-mode.

    Find:

    sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

    and change to

    sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

    or you can run the following in phpMyAdmin

    SET @@global.sql_mode='';

    0 讨论(0)
  • 2021-02-05 16:35

    You can use nullableTimestamps() instead of timestamps()

    or else

    $table->timestamp('created_at')->default(\DB::raw('CURRENT_TIMESTAMP'));
    

    also, check the database server version

    Please have a look on these ref links:

    https://github.com/laravel/framework/issues/3602

    https://laracasts.com/discuss/channels/forge/syntax-error-or-access-violation-1067-invalid-default-value-for-created-at

    0 讨论(0)
  • 2021-02-05 16:36

    This worked for me after being unsuccessful with strict mode:

    $table->timestamp('published_on')->useCurrent();
    
    0 讨论(0)
提交回复
热议问题