postgresql - Rails database table changed name, but index in another table refers to old name -
i changed table name "addresses" "locations". here 2 models
class location < activerecord::base has_many :years, dependent: :destroy has_many :people, through: :years class year < activerecord::base belongs_to :location belongs_to :person
i made change rename_table :addresses, :locations
migration , changed names of folders, files , references in relevant controllers , views. seems ok except years database still has column address_id
in years table. needs location_id
. can migrate change.? links newly named database preserved? i've backed database , made spreadsheet copy of years output.
an prechange version of project @ https://bitbucket.org/mtnbiker/crores5/src. i'm reluctant merge changes master until have sorted out.
thanks suggestions.
ps. don't recommend changing table name, had field named address in addresses table , wanted rid of confusion. needless say, i'm newbie.
i think thing you're looking rename column in years
table:
rename_column :table_name, :old_column, :new_column
perhaps
rename_column :years, :address_id, :location_id
after migration years table have location_id column have same values had in there before.
edit: not required have column particular name (though easier if app thing "rails way). can, example, define years model reference location model via column has "incorrect" name.
class year < activerecord::base belongs_to :location, foreign_key: :address_id, primary_key: :id
Comments
Post a Comment