SQLSTATE [23000]:违反完整性约束:19 CHECK约束失败:

时间:2020-09-09 17:22:20

标签: php sql laravel sqlite eloquent

我正在使用laravel 7.2进行项目,由于某些原因,我决定使用sqlite数据库,无论如何这还不错,但事实是,我对slite数据库了解不多。一切都很好,直到出现Integrity constraint violation: 19 CHECK constraint failed:错误为止。 好吧,我以为是我的代码“当然仍然可能是” 导致错误,直到我尝试将数据手动插入数据库表并得到enter image description here

我尝试从控制器插入数据

Merge::create([
       'user_id' => $query->user_id,
       'merge_id' => $to_be_merged->id,
       'investment_id' => $query->id,
       'file' => null,
       'merge_status' => 'pending',
       'merged_user_action' => 'pending',
       'merge_expiry' => Carbon::now()->addDay()
   ]);

这会导致此错误

SQLSTATE[23000]: Integrity constraint violation: 19 CHECK constraint failed: cashflow_merges (SQL: insert into "cashflow_merges" ("user_id", "merge_id", "investment_id", "file", "merge_status", "merged_user_action", "merge_expiry", "updated_at", "created_at") values (21, 47, 7, ?, pending, pending, 2020-09-10 16:23:41, 2020-09-09 16:23:41, 2020-09-09 16:23:41))

然后,再次出现 CHECK 约束错误。仍在试图找出那是什么意思。

迁移

 Schema::create('cashflow_merges', function (Blueprint $table) {
     $table->increments('id');
     $table->integer('user_id')->unsigned();
     $table->integer('merge_id')->unsigned();
     $table->integer('investment_id')->unsigned();
     $table->string('file')->nullable();
     $table->enum('merge_status', ['pending', 'denied', 'complete', 'canceled', 'expired']);
     $table->enum('merged_user_action', ['waiting', 'seen', 'expired']);
     $table->string('merge_expiry');
     $table->timestamps();
  });

1 个答案:

答案 0 :(得分:0)

在迁移中,merged_user_action字段没有pending枚举,但是您正在通过pending插入create statement。您只需要使用已定义的枚举值中的一个值即可。