[ACCEPTED]-Is rake db:migrate the correct command to re-sync schema.rb with your database schema?-rake
"rake db:migrate" will try and run all the 19 outstanding migrations for your project. If 18 you just want to dump the schema do a "rake 17 db:schema:dump".
But I think you have a 16 problem where it says that the table already 15 exists. One of your migrations is failing 14 because the table it is trying to add already 13 exists in your db. Did you create one by 12 hand? Did you down a migration, but not 11 have a down written for it? You will need 10 to fix this before you can write future 9 migrations. If it is just a mistake, and 8 the table is there and correct and you want 7 to ignore this. My recommendation is to 6 hack around it by commenting out the create 5 table in the failing migration. Then run 4 "rake db:migrate". Then but the create 3 table back. This will update your schema 2 version.
Make sure you write proper downs 1 on all migrations.
RAILS_ENV=development rake db:drop
RAILS_ENV=development rake db:migrate
and be happy!
Making sure that you run it on your test or development environment since this will drop the database/tables
I've found that occasionally, when things 11 get a little weird, you'll find yourself 10 in a situation where Rails will want to 9 run a migration that it ought rightly to 8 be considering already done (the table already 7 exists, etc). You can mark a migration 6 as done by finding its number (the number 5 part at the beginning of the filename), going 4 into mysql and issuing a query like so:
insert into schema_migrations values('20090521153438');
(or 3 whatever the number of your migration is)
Or 2 if it's a plugin migration being run using 1 Desert's migrate_plugin:
insert into plugin_schema_migrations values('my_plugin', '005');
rake db:migrate:reset will drop all your tables, run all the 1 migrations and create a new
rake db:schema:dump or
$ rake -T | grep schema rake db:schema:dump # Create a db/schema.rb file that is portable # against any database supported by ActiveRecord
rake db:schema:dump re-creates the
db/schema.rb file without running 4 any of your migrations again, or dropping 3 any tables (which implicates losing the 2 data in those tables), so it's the least 1 invasive way you can try first.
answering your last question regarding documentation:
- a guide to rails rake tasks for rails 2.1+: http://www.tutorialspoint.com/ruby-on-rails-2.1/rails-and-rake.htm
- a good screencast on migrations: http://railscasts.com/episodes/107-migrations-in-rails-2-1
More Related questions