【发布时间】:2011-12-02 18:49:38
【问题描述】:
我正在使用 Rails 3.0.9 和 Postgres 9.4 开发一个 Web 应用程序
我正在尝试为 has_and_belongs_to_many 关联创建一个连接表,但是当执行“rake db:migrate”时,唯一未执行的迁移是连接表的迁移。
Rails 没有显示任何错误,只是没有创建表。
当我进行回滚时,rails 显示错误,因为无法删除表,因为不存在。
这里是迁移的代码:
class CreateCampanaLocalJoinTable < ActiveRecord::Migration
def self.up
def change
create_table :campanas_locals, :id => false do |t|
t.integer :campana_id
t.integer :local_id
end
end
end
def self.down
drop_table :campanas_locals
end
end
有人有想法吗?谢谢!
【问题讨论】:
-
您已经在 up 方法中嵌套了一个方法定义。这不是真的执行 change 方法吗,因为它只是该方法的定义,而不是对其的调用?
标签: ruby-on-rails migration associations has-and-belongs-to-many