php - Laravel 没有将空值更新为外键列
问题描述
当我尝试更新记录并将它的外键添加到时,我遇到了 laravel 问题NULL
它根本没有更新。
没有错误,我也检查了Mass Assignment
。
迁移文件:
Schema::create('time_slots', function (Blueprint $table) {
$table->id();
$table->enum('duration', ['30', '60']);
$table->double('price', 6, 2)->nullable();;
$table->enum('currency', ['usd', 'egp'])->nullable();
$table->dateTime('start_time');
$table->dateTime('end_time');
$table->enum('status', ['available', 'booked', 'finished'])->default('available');
$table->enum('type', ['video', 'text', 'phone', 'not-set'])->default('not-set');
$table->unsignedBigInteger('session_id');
$table->foreign('session_id')->references('id')->on('sessions')->onDelete('cascade');
$table->unsignedBigInteger('patient_id')->nullable();
$table->foreign('patient_id')->references('id')->on('patients')->onDelete('cascade');
$table->timestamps();
});
更新查询
$timeslot->currency = null;
$timeslot->price = null;
$timeslot->patient_id = null;
$timeslot->status = 'available'; // that is the only column that update correctly
$timeslot->save();
解决方案
只需像这样替换货币定义
$table->enum('currency', [null,'usd', 'egp'])->nullable();
或这个
$table->enum('currency', ['usd', 'egp', null])->nullable()->default(null)
推荐阅读
- amazon-iam - Minio:密码更改策略
- javascript - 在 Javascript 中寻找最老的用户
- android - 程序类型已经存在:dagger.Binds
- c# - 如何将列表从我的第一个表单传递到第二个表单,向其中添加数据,然后在我的第一个表单上显示它?C#
- html - 将响应式卡片图像中的图标或按钮居中
- python - 如何在生成文件中添加多个标题(HDR)和对象?
- node.js - 为不同的用户分配不同的 url
- javascript - Discord Bot 使用 startWith() 找不到频道
- typescript - 打字稿交集类型 T 不可分配给类型 T&U
- reactjs - 将 jest-dom 匹配器与 puppeteer 对象一起使用