I have run into a very strange problem. I have a task which resets my database as so:
task :reset => [:drop, :create, :migrate, :seed]
The problem is, I am receiving errors when seeding because of missing columns which are added in late migration files. One example:
undefined method new_attr= for User
Yet this attribute is already added in a migration. The strange part is, I receive no errors if I run the above tasks separately. Can anybody shed some light? Surely these tasks cannot be run asynchronously.
Another way to avoid errors is to amend my earlier migrations create_ with the new attributes. Then running :reset doesn't trigger errors for those attributes.
The migrations are clearly fine as I can run the above tasks separately, just not bundled under a single task.
If these rake tasks are executed in the production mode, model attributes are cached. Even though migrations work perfect, it wont apply to the cached. This will break your succeeding seed as newly added columns will be missing in the cache. A possible solution is to reload your rails environment before seeding.
maybe you want to make your reset task more explicit?
Probably your problem is already solved using this:
The rake db:reset task will drop the database, recreate it and load the current schema into it.
Have you tried with namespace?