Reputation: 3334
The original issue is that some migration files were originally run on a machine (like production). Later, a few migrations were somehow deleted and could not be recovered.
So, to get a new machine up and running with the app, I had to manually recreate the missing migrations.
Thus, a machine that already performed the deleted migrations is now throwing these errors.
PG::Error: ERROR: relation "some_relation" already exists
I can't just db:reset
the db on production because I can't lose that data.
When I run, rake db:test:prepare
something like this shows up:
You have 4 pending migrations:
20130112203055 CreateSomeTable
20130113180203 AddSomeColumnToTable
20130113204017 ChangeSomeOtherColumns
20130311203729 CreateAnotherTable
Run `rake db:migrate` to update your database then try again.
Obviously, running db:migrate
will give the PG::Error as stated above. The problem is the schema changes have already been completed via the deleted migrations. The above 'pending' migrations had to be recreated after the fact.
Is there a way to fix this so db:migrate
works again?
Upvotes: 0
Views: 1236
Reputation: 2273
Try the following,
rake db:migrate:down VERSION=20121031XXXXXXXX
rake db:migrate
Where 20121031XXXXXXXX
is the date stamp of the migration name. In other words, you'll have a migration named 20120410214815_some_relation.rb
(like) and you copy the date stamp from the filename and paste it into the command. Here's the Rails Guide on Migrations for reference.
Upvotes: 1