【问题标题】:laravel updateOrCreate query null datalaravel updateOrCreate 查询空数据
【发布时间】:2020-09-19 17:21:47
【问题描述】:

尝试使用雄辩的方法 updateOrCreate() 没有成功,下面是我的代码

$myArray = ['nama_toko' => 'test', 'user_id' => 3];
Store::updateOrCreate(['user_id' => 2], $myArray);

它显示这样的错误:

null value in column "user_id" violates not-null constraint DETAIL: Failing row contains 
(22, test, null, 2020-09-20 01:14:30, 2020-09-20 01:14:30). 
(SQL: insert into "stores" ("nama_toko", "updated_at", "created_at") 
values (test, 2020-09-20 01:14:30, 2020-09-20 01:14:30) returning "id") 

为什么它没有正确读取我的数组(user_id)。 请帮忙,谢谢。

这是我的商店表:

public function up()
    {
        Schema::create('stores', function (Blueprint $table) {
            $table->id();
            $table->string('nama_toko');
            $table->bigInteger('user_id');
            $table->timestamps();
        });
    }

【问题讨论】:

  • user_id 在该模型上是否可填充?

标签: laravel laravel-7


【解决方案1】:

确保将 user_id 作为可填充属性添加到您的模型中。

【讨论】:

  • 谢谢,我认为需要阅读更多关于该大规模作业的信息
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-07-30
  • 1970-01-01
  • 1970-01-01
  • 2023-03-04
  • 2018-01-23
  • 2015-01-22
  • 2021-09-24
相关资源
最近更新 更多