I recently ran into an error when I tried to change the column name in my schema. It worked locally, but when I db:migrated on Heroku, it gave me an error saying that the column didn’t exist.
In the past, I’ve been bad with unifying my Production schema and Development Schema. This is probably because I created migrations locally, ran db:migrate locally, and then deleted the migrations locally for some reason and then pushed to heroku, resulting in the migration being run locally but not in prod. (I now know this is a terrible thing to do, and I should have typed in the opposite function in self.down and did rake db:rollback)
What I want to know is, how do I check to see if my local and prod schema are different, and is there a way that I can just change my local tables/columns to fit the productions’? Since it seems to work with only the production stuff and I know I have useless tables/columns in my local env.
You can run a bash console on Heroku with:
From there you can navigate the filesystem using the standard bash commands and cat your
schema.rbfile to compare to your localschema.rb.To unify the schema I would suggest reading through the detail on Schema dumping in the Rails Guide to Migrations. You would copy the schema file over to your local environment, and then run `rake db:reset’ which will drop your development database and recreate it from the new schema. Be sure to read the Schema Dump details as there is more than one way to dump the schema depending on the needs of your database. And obviously, backup whatever you need to before your start.
From that point on you should be back to clean slate where you can start migrations correctly again to update your local app and Heroku.