Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Devise primary key error on postgresql, heroku, Rails 4 [duplicate]

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

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.
like image 224
Pedro Bernardes Avatar asked Jul 25 '14 14:07

Pedro Bernardes


1 Answers

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

like image 155
Yana Agun Siswanto Avatar answered Oct 31 '22 22:10

Yana Agun Siswanto