我在数据透视表中保存数据时出现以下错误
Not null violation: 7 ERROR: null value in column "created_at" violates not-null constraint DETAIL: Failing row contains (4, 10, 16, null, null). (SQL: insert into "child_packages" ("child_id", "package_id") values (10, 16))
这是我在表格中保存数据的代码
$child = $this->child_section->create($input);
$packages_ids = Input::get('package_id');
$child->Packages()->sync($packages_ids);
并在儿童模型中
public function Packages()
{
return $this->belongsToMany('FoodPackage');
}
对于数据库我正在使用postgresql
答案 0 :(得分:1)
你有添加方法 whitTimestamps();
示例:
$this->belongsToMany(Model::class)->withTimestamps();
https://laravel.com/docs/8.x/eloquent-relationships#has-many-through