我正在使用Ruby on Rails 3,我想将SQL数据库表的默认主键从id
更改为account_id
。 account_id
语句和行为应与id
相同(自动增量,唯一,...)。
在我的迁移文件中,我尝试了以下内容:
create_table :users, :id => false do |t|
t.integer :account_id
...
t.timestamps
end
add_index :users, :account_id, :primary => true
但是使用MySQL Workbench,当我尝试编辑'users'表时,我收到此错误:
'users': table is not editable because there is no primary key defined for the table
那么,如何正确设置“用户”表的主键?
答案 0 :(得分:0)