2011-03-19 58 views
0

我正在使用Ruby on Rails 3,并且想要将SQL数据库表的默认主键从id更改为account_idaccount_id声明和行为应该与id(自动递增,唯一,...)相同。更改数据库表的默认主键时遇到问题

在我的移民文件,我tryed如下:

create_table :users, :id => false do |t| 
    t.integer :account_id 
    ... 

    t.timestamps 
end 
add_index :users, :account_id, :primary => true 

但使用MySQL Workbench,当我尝试编辑 '用户' 表中,我得到这个错误:

'users': table is not editable because there is no primary key defined for the table 

所以,我如何正确设置我的'用户'表的主键?

+2

检查http://stackoverflow.com/questions/750413/altering-the-primary-key-in-rails primary_key选项以诚待一个字符串 – 2011-03-19 17:22:08

回答