【问题标题】:Error Number: 1364 Field 'modified_at' doesn't have a default value错误号:1364 字段“modified_at”没有默认值
【发布时间】:2019-12-09 07:59:28
【问题描述】:

当我尝试将严格值设为 TRUE 时,它会显示错误 Error Number: 1364 Field 'modified_at' doesn't have a default value",当我尝试将其设为 FALSE 时,它会显示错误

Variable 'sql_mode' can't be set to the value of 'REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE( @@sql_mode'
SELECT GET_LOCK('ad3549572403a9c71bea1109d26f4b48', 300) AS ci_session_lock

当值为 true 时,一切正常,但我需要刷新才能出错:“错误编号:1364 字段 'modified_at' 没有默认值”消失了。 请帮助我克服这个错误。 谢谢你!

这是错误的截图:

enter image description here

enter image description here

【问题讨论】:

    标签: php codeigniter-3 codeigniter-2


    【解决方案1】:

    使该列可以为空。因为这里 modified_at 不可为空。当您保存行数据时,您传递了每个元素,但您没有将任何数据保存到 modified_at。所以让这个列可以为空。

    $table->date('modified_at')->nullable();
    

    如果你没有足够的数据,那么

    php artisan migrate:refresh
    

    如果您有足够的数据库数据并且不想刷新它,请添加一个新的迁移文件。 & 使这个列可以为空。就像

    Schema::table('your_table_name', function (Blueprint $table) {
        $table->string('modified_at')->nullable()->change();
    });
    
    

    了解详情 https://laravel.com/docs/5.8/migrations#modifying-columns

    【讨论】:

      【解决方案2】:

      您在插入数据时没有将值传递给“modified_at”列,因此会引发错误。

      您应该使该列具有默认值或查看列名,我猜想将其设为可空即可。

      (假设该列是日期字段并使用 Laravel)

      你必须使用Column modifier ->nullable()

      迁移:

      $table->date('modified_at')->nullable();
      

      .

      【讨论】:

        猜你喜欢
        • 2013-03-04
        • 2019-11-23
        • 2013-09-16
        • 1970-01-01
        • 2021-02-28
        • 2021-10-13
        • 2017-03-02
        • 2020-02-03
        相关资源
        最近更新 更多