I'm trying to add my Address
table's text
property as the address
property of my Brewery
table, then delete the Address
table. I'm doing this on Heroku after a git push heroku master
by running heroku run rake db:migrate
.
My first migration which creates the new field for the data works fine. But my second migration fails immediately- it says it can't find the Address
table. My third migration never runs, but it's the one that was supposed to delete the Address
table to tidy everything up.
What am I doing wrong? These migrations worked on my local box, but are failing on Heroku:
class AddAddressStringToBrewery < ActiveRecord::Migration
def change
add_column :breweries, :address, :string
end
end
class MoveAddressToString < ActiveRecord::Migration
def change
Address.all.each do |address|
brewery = address.brewery
brewery.update(address: address.text)
end
end
end
class DropAddressTable < ActiveRecord::Migration
def change
drop_table :addresses
end
end
My best guess is that Heroku is reading my schema and dropping the table, before running my migrations. I could always stage these migrations in individual git commits to force it to work, but I'd really like to know where I went wrong.
Thanks!
I realized what I did wrong. My push to Heroku with these migrations also deleted my Address model. When I ran them in my local environment it was before I cleaned up the old Address code. I added the Address model back long enough to run the migrations and they all run fine.