Experienced with Rails / ActiveRecord 2.1.1
- You create a first version with (for example) ruby script\generate scaffold product title:string description:text image_url:string
- This create (for example) a migration file called 20080910122415_create_products.rb
- You apply the migration with rake db:migrate
- Now, you add a field to the product table with ruby script\generate migration add_price_to_product price:decimal
- This create a migration file called 20080910125745_add_price_to_product.rb
- If you try to run rake db:migrate, it will actually revert the first migration, not apply the next one! So your product table will get destroyed!
- But if you ran rake alone, it would have told you that one migration was pending
Pls note that applying rake db:migrate (once the table has been destroyed) will apply all migrations in order.
The only workaround I found is to specify the version of the new migration as in:
rake db:migrate version=20080910125745
So I’m wondering: is this an expected new behavior?
You should be able to use
to force it to go forward, but then you risk missing interleaved migrations from other people on your team
if you run
twice, it will reapply all your migrations.
I encounter the same behavior on windows with SQLite, it might be a bug specific to such an environment.
Edit — I found why. In the railstie database.rake task you have the following code :
Then in my environment variables I have
in Ruby
thus the rake task calls
and in ActiveRecord::Migrator we have :
Yes,
rake db:migrate VERSION=0is the long version forrake db:migrate:downEdit – I would go update the lighthouse bug but I the super company proxy forbids that I connect there
In the meantime you may try to unset Version before you call migrate …