laravel updateOrCreate 查询空数据
laravel updateOrCreate query null data
尝试使用 eloquent 方法 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)。
请帮助和感谢。
这是我的商店 table :
public function up()
{
Schema::create('stores', function (Blueprint $table) {
$table->id();
$table->string('nama_toko');
$table->bigInteger('user_id');
$table->timestamps();
});
}
确保将 user_id 添加到您的模型中作为可填充的 属性。
尝试使用 eloquent 方法 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)。 请帮助和感谢。
这是我的商店 table :
public function up()
{
Schema::create('stores', function (Blueprint $table) {
$table->id();
$table->string('nama_toko');
$table->bigInteger('user_id');
$table->timestamps();
});
}
确保将 user_id 添加到您的模型中作为可填充的 属性。