samedi 6 juillet 2019

Laravel fills attributes in model in migration even though they are not fillable

I have two entities:

  1. Person, which has workspace_id column
  2. PersonRevision, which does not have workspace_id column

In a migration I have this:

$persons = Person::all();

foreach ($persons as $person) {
    $revision = new PersonRevision;
    $revision->fill($person->getAttributes());
    $revision->save();
}

PersonRevision does not have workspace_id in fillable property. But for some reason I got an error: column "workspace_id" of relation "person_revisions" does not exist.

Besides, if I run the migration second time (by just typing php artisan migrate second time) it works fine.

What could be the reason? I know I can manually list attributes which need to be filled, or use array_except but this is inconvenient and does not answer why that happens.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire