laravel - laravel updateOrCreate 查询空数据
问题描述
尝试使用雄辩的方法 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 作为可填充属性添加到您的模型中。
推荐阅读
- xml - 无法使用 groovy 将环境变量添加到 pom.xml 文件
- salesforce - 将闪电组件推送到 salesforce org 时出错
- android - 如何使用 react-native 实现 Word-Link 游戏中使用的滑动手势
- ios - TableView 部分索引不显示
- python - 使用 python 进行 Mongo 查询
- amazon-web-services - 如何使用 Cost explorer API 在 AWS 中查找未标记资源的成本
- sql-server - 即使为其他查询结果复制了参数,查询也没有结果
- ios - 不同颜色的标题区域
- image - 对使用图像数据生成器设置 steps_per_epoch 感到困惑
- java - Java 命令行计算器帮助。添加数字序列