开发者

Rails3,'add_index' method doesn't work when I try to add 3 column

when i deal with a migrate data,i want to make each record unique in the table the migrate file make.here is my migrate file:

  def self.up
    create_table :rbac_mandat开发者_如何学JAVAa do |t|
      t.integer :mandator_id
      t.integer :mandatarius_id
      t.integer :permission_id

      t.timestamps
    end
  add_index :rbac_mandata, [:mandator_id, :mandatarius_id, :permission_id], :unique => true
  end

when i execute rake task and find it not work.but when i change it to this,it was done:

  def self.up
    create_table :rbac_mandata do |t|
      t.integer :mandator_id
      t.integer :mandatarius_id
      t.integer :permission_id

      t.timestamps
    end
  add_index :rbac_mandata, [:mandator_id, :permission_id], :unique => true
  end


The generated index name is probably too long, it's probably over 64 characters. Just define the name manually and it'll go through fine, like this...

add_index :rbac_mandata, [:mandator_id, :mandatarius_id, :permission_id], :unique => true, :name => 'my_index_name_here'
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜