2015-09-15 45 views

回答

1
class AddProductWithDifferentPrimaryKey < ActiveRecord:Migration 
    def change 
    create_table :table, id: false do |t| 
     t.string :id, null: false 
     # other columns 
     t.timestamps 
    end 
    execute "ALTER TABLE table ADD PRIMARY KEY (id);" 
    end 
end 

不要忘了也该行添加到您的表格模型,以便轨知道如何找到新的主键!

class Product < ActiveRecord::Base 
    self.primary_key = :id 

    # rest of code 
end 

希望这会有所帮助。和信贷应该去 A K H

对于你可以看看他还有其它一些问题的更多信息。 primary key info

+0

谢谢,但我该如何将字符串序列添加到rails应用程序本身的主键,或者我应该为它创建一个PLSQL序列。 –

相关问题