0

I am getting following error while saving the data in the pivot table

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))

here is my code for saving data in the table

    $child = $this->child_section->create($input);


    $packages_ids = Input::get('package_id');
    $child->Packages()->sync($packages_ids);

and in the child model

 public function Packages()
{
    return  $this->belongsToMany('FoodPackage');
}

For database I am using postgresql

HKumar
  • 1,535
  • 3
  • 13
  • 28

1 Answers1

1

You have add method whitTimestamps();

Example:

$this->belongsToMany(Model::class)->withTimestamps();

https://laravel.com/docs/8.x/eloquent-relationships#has-many-through