开发者

Rails 3: habtm migration, primary key issue

I'm trying to setup a migration file for a habtm relationship, however when I run the migration I'm getting the following error:

Primary key is not allowed in a has_and_belongs_to_many join table (parts_vehicles).

Here is my migration file (20110111035950_crea开发者_Python百科te_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

The documentation example states to use :id => false to disable a primary key from being generated, but I'm still getting the error.


1.) You're class name should be the same as your migration name:

class CreatePartsVehicles < ActiveRecord::Migration

2.) Did you migrate? Try dropping your db (rake db:drop) and remigrating (rake db:migrate)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜