Reputation: 671
Okay, this is what happened:
1) I needed to add a column to a table but instead of generating the migration I wrote it by hand. The file name I gave it seemed to work okay but didn't have a timestamp so then things went bad.
2) After messing about for ages I updated the schema.rb file so that it looked the way I wanted. Then I reset the database. That was fine but ...
3) When i went to run the migrations the last few had already been run so it thought they were duplicates. So I deleted all the migrations because the schema looked fine and everything was working well.
4) But now it works fine on my local machine but I'm having real issues when I try to deploy to Heroku, which seems to have access to my old migrations and is denying the existence of a table that is clearly there. I've reset a bunch of times.
So, is there some way I can start again with the schema and no migrations and get the system to forget there ever were migrations? Or what if I create two new migrations that contain all the relevant table data?
EDIT: This is what I'm getting from heroku logs. Basically it lets me get to the login page but when I try to sign in this happens.
Started GET "/home" for 89.27.92.12 at 2013-02-19 18:27:01 +0000 2013-02-19T18:27:01+00:00 app[web.1]: 2013-02-19T18:27:01+00:00 app[web.1]: Processing by MaterialsController#home as HTML 2013-02-19T18:27:01+00:00 app[web.1]: Completed 500 Internal Server Error in 26ms 2013-02-19T18:27:01+00:00 app[web.1]: 2013-02-19T18:27:01+00:00 app[web.1]: ActiveRecord::StatementInvalid (PGError: ERROR: relation "materials" does not exist 2013-02-19T18:27:01+00:00 app[web.1]: LINE 4: WHERE a.attrelid = '"materials"'::regclass 2013-02-19T18:27:01+00:00 app[web.1]: ^ 2013-02-19T18:27:01+00:00 app[web.1]: FROM pg_attribute a LEFT JOIN pg_attrdef d 2013-02-19T18:27:01+00:00 app[web.1]: : SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull 2013-02-19T18:27:01+00:00 app[web.1]: WHERE a.attrelid = '"materials"'::regclass 2013-02-19T18:27:01+00:00 app[web.1]: AND a.attnum > 0 AND NOT a.attisdropped 2013-02-19T18:27:01+00:00 app[web.1]: ON a.attrelid = d.adrelid AND a.attnum = d.adnum 2013-02-19T18:27:01+00:00 app[web.1]: ): 2013-02-19T18:27:01+00:00 app[web.1]: app/controllers/materials_controller.rb:11:in `get_materials' 2013-02-19T18:27:01+00:00 app[web.1]: ORDER BY a.attnum
Upvotes: 0
Views: 220
Reputation: 18845
this sounds really messed up!
PGError: ERROR: relation "materials" does not exist
clearly states that this table is missing in the schema.
you can have a look at the current migration state by looking into the db directly: ActiveRecord::Base.connection.execute("SELECT * from schema_migrations").map(&:to_s)
you could also dump the database and have a look localy: https://devcenter.heroku.com/articles/heroku-postgres-import-export
Upvotes: 1