Devise primary key error on postgresql, heroku, Ra

2019-05-01 06:25发布

问题:

This question already has an answer here:

  • Rails auto-assigning id that already exists 4 answers

It is really odd, I'm trying to create a new user by command line and I'm getting this error:

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.

回答1:

Try This

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

Source: https://stackoverflow.com/a/15108735/3034747