我正在尝试为habtm关系设置一个迁移文件,但是,当我运行迁移时,我会得到以下错误:
has_and_belongs_to_many联接表(parts_vehicles)中不允许主键。
下面是我的迁移文件(20110111035950_create_parts_vehicles.rb):
class CreatePartsVehiclesJoinTable < ActiveRecord::Migration
def self.up
create_table :parts_vehicles, :id => false do |t|
t.integer :part_id
t.integer :vehicle_id
end
end
def self.down
drop_table :parts_vehicles
end
end文献资料示例声明使用:id => false禁用生成的主键,但我仍然会收到错误。
发布于 2011-01-11 04:51:06
1.)您的类名应该与迁移名称相同:
class CreatePartsVehicles < ActiveRecord::Migration2.)你迁徙了吗?尝试删除db (rake :drop)和重新迁移(rake :migrate)
https://stackoverflow.com/questions/4654283
复制相似问题