php - Laravel model is created with id = 0 -


i having problem eloquent. here's code:

$basetask = $taskclass::create([         'user_id' => $user->id,         'task_type' => $this->task_type,         'name' => $this->settings['name'],         'task_' . $this->social_network . '_list_id' => $task_list_id, ]); $basetask->accounts()->attach($account_id); 

the problem sometimes last line fails foreign key constraint fails - tries update pivot table query

insert pivot ('account_id', 'task_id') values (289530, 0)) 

so somehow:

$basetask->id=0; 

but have property:

$incrementing=true; 

maybe faced such issue, appreciated!

use save() method instead, since don't have many many relationship. if have many many use sync() function then. go database.php file set mysqlstrict false


Comments

Popular posts from this blog

python 2.7 - Given three nested dictionaries, sort the top two nested dictionaries from a value in the innermost dictionary? -

angular - DownloadURL return null in below code -