更改数据库表的默认主键时出现问题

时间:2011-03-19 17:06:33

标签: sql ruby-on-rails ruby ruby-on-rails-3 primary-key

我正在使用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

那么,如何正确设置“用户”表的主键?

1 个答案:

答案 0 :(得分:0)