Open
Description
or cause serious data corruption
Can you think of a use case when an old migration could cause a serious data corruption?
Yes, it will most probably break db:migrate
on a clean database.
- There's yet another reason not to use real models in migrations.
If you refer to a real model in an older migration (e.g. forupdate_all
), Rails will cache column information.
And subsequent migrations that would alter that table's schema won't affect the column cache.
This will lead to breakages due to an outdated (fixed for the moment when the model was first referred to in migrations) table schema. Specifically, if you add a column in a later migration andupdate_all
that new column, this will result in an error.
Also, if you runrake db:migrate db:seed
in one command, this will also affect your seeds, and it will also fail with:
ActiveModel::UnknownAttributeError: unknown attribute 'some_attr' for ModelName
Metadata
Metadata
Assignees
Labels
No labels