Reputation: 4516
I've a PostGresql database on my local system. I used it during development and I'm trying to test it out on the Heroku system.
Note I'm using PostGresql so that I can make use of the schemas.
I'm running the system perfectly on my local system.
I go to the Heroku page on how to push my DB to the server. http://devcenter.heroku.com/articles/taps
> heroku db:push
After about 5 minutes I get
"PGError: ERROR: relation "schema_migrations" does not exist"
What I'm wondering is two fold.. On a minor level I am wondering why this is happening. Is my database being reconstructed from scratch? On a major level, I'm wondering how to I get around this.
Brief: How do I get around the missing table on a db:push?
To address concerns expressed in the answer given.
W:\RUBY\EDM>heroku run rake db:create
Running rake db:create attached to terminal... up, run.1
kzcgkswrss already exists
W:\RUBY\EDM>heroku run rake db:migrate
Running rake db:migrate attached to terminal... up, run.1
W:\RUBY\EDM>heroku db:push
Loaded Taps v0.3.23
Auto-detected local database: postgres://postgres:[email protected]/EDM2_develo
pment?encoding=utf8
Warning: Data in the app 'xxxx' will be overwritten and will not be r
ecoverable.
! WARNING: Potentially Destructive Action
! This command will affect the app: xxxx
! To proceed, type "xxxx" or re-run this command with --confirm c
xxxx
> xxxxx
Sending schema
Schema: 100% |==========================================| Time: 00:01:56
Sending indexes
schema_migrat: 100% |==========================================| Time: 00:00:01
....
users: 100% |==========================================| Time: 00:00:02
Sending data
31 tables, 5 records
schema_migrat: 0% | | ETA: --:--:--
Saving session to push_201202150351.dat..
!!! Caught Server Exception
HTTP CODE: 500
Taps Server Error: PGError: ERROR: relation "schema_migrations" does not exist
It seems this error is related to a second schema that exists in postGresql.. It looks like it pushed all the empty tables in the public, but as soon as it tried to push up the second schema, it failed..
Upvotes: 1
Views: 6993
Reputation: 2787
did you run your migrations on heroku itself?
$ heroku run rake db:migrate
If you didn't then probably that's it
Upvotes: 0
Reputation: 14750
Try
heroku rake db:push
Or perhaps if that doesn't work, do
heroku rake db:migrate
first, and then try the second.
You're getting the missing table because you haven't created the table yet on Heroku. You need to create the DB and run the migrations. Yes, this will create a new DB.
UPDATE:
To quote Daniel Vandersluis (from this link):
When you use rails migrations, a table called schema_migrations is automatically created, which keeps track of what migrations have been applied, by storing the version number of each migration (this is the number that prefaces the migration name in the file name, ie db/migrate/_20090617111204__migration.rb). When you run rake db:migrate to migrate up, only migrations which have not been run previously (ie. their version is not contained in the table) will be run (for this reason, changing a migration that's already been executed will have no effect when running db:migrate). When migrating down, all versions found in schema_migrations that are greater than the version you are rolling back to will be undone.
Upvotes: 1