在postgresql,heroku,Rails 4上设计主键错误

Ped*_*des 5 postgresql ruby-on-rails heroku devise

这真的很奇怪,我正在尝试通过命令行创建一个新用户,我收到此错误:

User.create :email => "pheewq+1@gmail.com", :password => '123456789', :password_confirmation => '123456789'

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

Yan*_*nto 20

试试这个

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

资料来源:https: //stackoverflow.com/a/15108735/3034747