Reputation: 1912
Let's say I wrote a migration to change one of the table name.
class RenameFooToBar < ActiveRecord::Migration
def change
rename_table :foos, :bars
end
end
After db:migration
and a reload!
in rails console
I was expecting to be able to use the class Bar
to refer to the renamed table i.e. Bar.create(name: 'bar1')
. But it gives me a NameError, so what did I missed or how do I setup this relation manually?
Upvotes: 0
Views: 695
Reputation: 44685
Renaming table is not enough, you need to rename app/models/foo.rb
to app/models/bar.rb
and also change the class name inside this file from class Foo < ActiveRecord::Base
to class Bar < ActiveRecordBase
. Also scan for any usage of constant Foo
.
Upvotes: 1