经验丰富的Rails/ActiveRecord 2.1.1
- You create a first version with (for example) ruby scriptgenerate 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 scriptgenerate 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
请注意,应用rake-db:migrate(一旦表被销毁)将按顺序应用所有迁移。
我找到的唯一解决方法是指定新迁移的版本,如下所示:
rake db:migrate version=20080910125745
所以我想知道:这是一种预期的新行为吗?