2011-03-19 62 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

回答