0

I have posted a couple other questions about a project I am working on, and I finally got it working to how I want it to.

I uploaded my stuff to heroku, and had to spend a couple hours figuring out how to get rid of all instances of sqlite3 and switch to PG. I got that fixed, but was still getting an error. Turned out to be a migration.

I ran heroku open and got the error page. I ran heroku logs and got this error;

2014-01-08T22:51:29.356850+00:00 app[web.1]: PG::Error: ERROR:  relation "messages" does not exist
2014-01-08T22:51:29.356850+00:00 app[web.1]: LINE 1: SELECT "messages".* FROM "messages"

That error I remembered was for not running your migrations. So I then ran bundle exec rake db:migrate, and then heroku run rake db:migrate and I got the error;

Running `rake db:migrate` attached to terminal... up, run.9247
rake aborted!
Multiple migrations have the name CreateMessages
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/migration.rb:978:in `validate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/migration.rb:876:in `initialize'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/migration.rb:764:in `new'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/migration.rb:764:in `up'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/migration.rb:742:in `migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/railties/databases.rake:42:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

Originally I had 2 migration files with the same thing because I forgot about migrations. I manually went into db/migrate and deleted one of them. I then did

git add .
git commit -m "message"
git push

then I ran

git push heroku master

to try and get it on the same level, but I still have this error. Does anyone know what I could do to fix this? Any help would be amazing.

Community
  • 1
  • 1
user1804592
  • 137
  • 3
  • 11
  • Did you get that message locally or on the heroku command? From `bundle exec rake db:migrate` or from `heroku run rake db:migrate` – nzifnab Jan 08 '14 at 23:21
  • You are doing a drop and create before migrate, right? – Tony Hopkinson Jan 08 '14 at 23:23
  • 1
    You've deleted the file, but git add does not remove it from the repository. git rm sounds more like what you want. – David Aldridge Jan 08 '14 at 23:29
  • @nzifnab I got the message from the heroku command. – user1804592 Jan 08 '14 at 23:43
  • @TonyHopkinson I just did (I forgot) and ran it locally. I ran `heroku run rake db:drop` and got FATAL: permission denied for database "postgres" DETAIL: User does not have CONNECT privilege. – user1804592 Jan 08 '14 at 23:45
  • @DavidAldridge I ran `git rm db/migrate/20140103233510_create_messages.rb` and deleted it – user1804592 Jan 08 '14 at 23:46
  • for what you've removed that file? once a migration added, it becomes required in the project always. – Малъ Скрылевъ Jan 09 '14 at 07:24
  • 1
    Please refer to the answer http://stackoverflow.com/questions/19097558/pg-undefinedtable-error-relation-users-does-not-exist/19804714#19804714 and make sure that reinitialize DB from a scratch is passed on local pc, otherwise you need to fix your migrations, and only then you shell to push into heroku. – Малъ Скрылевъ Jan 09 '14 at 07:26
  • @majioa thank you so much! That worked, and I got it live on heroku. I just have to set up another for private pub/faye to work on heroku. – user1804592 Jan 10 '14 at 00:00

2 Answers2

2

FIRST: it's my understanding that you are ok with resetting your db instance. If that's correct, keep reading Option 1:

Option 1:

First reset your db: heroku pg:reset as noted here

Then confirm that you have indeed remove your conflicting migrations. Proceed with any git push if you need.

At this point, re-migrate your db:

heroku run rake db:migrate

Option 2:

Please comment below if you are not planning to reset your DB. It becomes a whole lot trickier then, and the right solution is probably more migrations or roll backs to fix your schema.

sybohy
  • 1,856
  • 2
  • 20
  • 25
1

Once a migration have been added, it becomes required all time when the project is exist. So you can only add migrations, and not remove them. If you have did a mistake in a migration rule, just add another rule that shell revert or fix your changes.

Please refer to the answer on how to do or redo migrations, and make sure that reinitialize DB from a scratch is passed on local PC, otherwise you need to fix your migrations, and only then you shell be able to push into heroku.

Community
  • 1
  • 1
Малъ Скрылевъ
  • 16,187
  • 5
  • 56
  • 69