2014-07-25 35 views
4

這是非常奇怪的,我試圖通過創建命令行一個新的用戶,我收到此錯誤:設計主鍵錯誤,Heroku的,軌道4,5

User.create :email => "[email protected]", :password => '123456789', :password_confirmation => '123456789' 

PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "users_pkey" 
DETAIL: Key (id)=(37) already exists. 

回答

13

試試這個

$ heroku run rails console 
irb(main)> ActiveRecord::Base.connection.tables.each { |t|  ActiveRecord::Base.connection.reset_pk_sequence!(t) } 

來源: https://stackoverflow.com/a/15108735/3034747

+0

我怎麼做相同的,但與laravel PHP? –

+0

@ChristopherFrancisco如果你有訪問數據庫直接http://stackoverflow.com/questions/244243/how-to-reset-postgres-primary-key-sequence-when-it-falls-out-of-sync – Yana