Laravel模型创建时id = 0

I am having problem with eloquent. Here's some 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 is that SOMETIMES the last line fails with a foreign key constraint fails - it tries to update pivot table with query

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

So somehow:

$BaseTask->id=0;

but i have property:

$incrementing=true;

Maybe someone faced such issue, any help appreciated!

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

I have experienced the same issue, you need to put:

public $incrementing = false;

on the model.