【问题标题】:SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'status' cannot be nullSQLSTATE [23000]:违反完整性约束:1048 列“状态”不能为空
【发布时间】:2019-04-14 19:31:23
【问题描述】:

我尝试为状态设置布尔值,但我发现“状态”列不能为空。我该怎么办?下面是我为创建用户表设置的代码。

public function up()
{
    Schema::create('users', function (Blueprint $table) {


        $table->increments('id');
        $table->string('name');
        $table->string('email')->unique();
        $table->string('password');
        $table->string('role')->nullable();
        $table->boolean('status');
        $table->string('address')->nullable();
        $table->string('city')->nullable();
        $table->string('postal_code')->nullable();
        $table->string('phone')->nullable();
        $table->rememberToken();
        $table->timestamps();
    });
}

【问题讨论】:

    标签: php laravel


    【解决方案1】:
    $table->boolean('status')->nullable($value = true); 
    

    允许(默认情况下)将 NULL 值插入列中

    【讨论】:

      【解决方案2】:

      status 列设置默认值

      $table->boolean('status')->default(0);
      

      【讨论】:

        【解决方案3】:
        • 检查您是否正在插入数据状态的插入时间值为空。 如果您有发送状态值,请将插入代码发送给我...

        【讨论】:

          猜你喜欢
          • 2021-02-01
          • 2019-11-20
          • 2021-08-16
          • 2019-10-06
          • 2020-10-25
          • 2017-02-28
          • 2017-04-15
          • 2017-12-26
          • 2019-11-24
          相关资源
          最近更新 更多