A common problem with records that have mysteriously lost some of the data provided to the new Entity is that Entity does not define the fields in question as _accessible .
Cake BakeShell will skip the primary key fields when generating new Entity classes for you, for example:
<?php namespace App\Model\Entity; use Cake\ORM\Entity; class Widget extends Entity { protected $_accessible = [
There are several ways around this.
You can modify your Entity class to make the id field permanently assignable:
protected $_accessible = [ 'id' => true, // Now `id` can always be mass-assigned. 'title' => true, ];
Or you can set your call to newEntity() to disable mass assignment protection:
$entities = $table->newEntity($data, [ 'accessibleFields' => ['id' => true], ]);
I found the most important damage when you are having problems with Cake 3 DB data is to double-check Entity as soon as it is created or fixed, and compare it with your input. You should still have a keen eye, but it will be shown that the objects did not have their property ->id , even if $data defined them.
source share