When you checkout a new project from scratch, you shouldn't use migrations to build the database.
You should use rake db:schema:load
instead.
Let me show you why.
Let's assume you create a new Post
model with a post table on migration 10.
On migration 11, you execute some special elaborations on the Post
model.
After a while, you decide to drop the Post
model and the post table because no longer required.
Six month later, you checkout the project from scratch. If you try to run rake db:migrate
the migration 11 will fail complaining about missing model. It's true, the model has been removed many month before and it's no longer available.
Instead, if you run rake db:schema:load
you'll initialize the database with the right schema version.
Talking about migrations, if you just created the postcode method and you are trying to use the _changed? magic method in the same migration, you need to reload the schema before.
class MigrationFile < ...
self.up
add_column :user, :postcode, :string
User.all.each { |user| puts user.postcode_changed? } # will fail
User.reset_column_information
User.all.each { |user| puts user.postcode_changed? } # now it works
end
...
end