【发布时间】:2018-02-14 19:04:48
【问题描述】:
我一次只需要插入 1 个 JSON 数组,因此如果没有条目,则 JSON 数组需要默认为 null。有什么办法可以做到吗?
使用来自:https://github.com/laravel/framework/issues/16107的方法
我的迁移是
Schema::create('job_details', function (Blueprint $table) {
$table->integer('id')->default('0');
$table->primary('id');
$table->foreign('id')->references('id')->on('job_searches');
$table->json('Location_of_job');
$table->json('API_URL');
$table->json('Redirected_URL');
$table->json('Description');
$table->json('Salary',6,2);
$table->timestamps();
});
型号:
protected $primaryKey = 'id';
public $timestamps = true;
protected $fillable = ['API_URL', 'Redirected_URL','Location_of_job','Description','Salary',];
protected $casts = [
'Location_of_job' => 'array',
'API_URL' => 'array',
'Redirected_URL' => 'array',
'Description' => 'array',
'Salary' => 'array'
];
protected $attributes = array(
'json' => '{}'
);
获取错误:
SQLSTATE[23502]:非空违规:7 错误:列中的空值 “Location_of_job”违反非空约束细节:失败行 包含(0,空,空,空,空,空,空,空)。 (SQL:插入 进入“job_details”(“API_URL”)值(),(),(),(),(),(),(),(), (), (), (), (), (), (), (), (), (), (), (), ())
【问题讨论】:
标签: php laravel postgresql