Schema rb not updating
To illustrate: a developer may very well write a migration, run indicates, whereas their production environment's schema—itself the product of only the sum of all deployed migrations—may differ in non-trivial and surprising ways.
While as a general rule it's advisable never to modify a deployed migration, if the alternative is "all our migrations are broken forever", it's worth finding a minimally invasive fix.
At least some of the blame lies with Rails itself for using the same load strategy when running migrations as it uses when loading the entire application.
(If it were up to me, I'd make everything under off-limits to migrations.) And while I'm perfectly content just dictating that one shouldn't do this, it may help to have a longform illustration at hand as to how referencing models from migrations can come back to bite you.
(Not to mention that writing complex data migrations in raw SQL is terrifically difficult in comparison to accomplishing most other SQL tasks, yet we adopted an ORM to avoid even those cases.) If you've written migrations that depend on loading your application's actual Active Record models, take comfort in knowing you're not alone, because Rails developers seem to inadvertently do this all the time.Before Rails, most teams I encountered were in the habit of making incredibly error-prone ad hoc changes to each of their application's databases.It's one part of the framework I wish were emulated much more broadly than it has been.Every time I add a new migration and see it succeed, I always make sure its hook, because some operations will succeed while migrating forward and only fail when reversed.(Rails 4 corrected a number of these cases, but errors can still crop up.) Suppose your application has a There's a glaring impedance mismatch here, if you think about it.
If a project reaches a point where old migrations can no longer be run, the team is left to trust the veracity of a generated file that they can no longer validate.