Skip to content

Instantly share code, notes, and snippets.

@ZephiroRB
Last active August 5, 2018 00:05
Show Gist options
  • Save ZephiroRB/c9bdf93e4192533d66c7e2683098b823 to your computer and use it in GitHub Desktop.
Save ZephiroRB/c9bdf93e4192533d66c7e2683098b823 to your computer and use it in GitHub Desktop.
Rails (PG::Error: ERROR: duplicate key value violates unique constraint "table_pkey" DETAIL: Key (id)=(1) already exists.
#I found the reset_pk_sequence! from this thread. http://www.ruby-forum.com/topic/64428
#rails console
ActiveRecord::Base.connection.tables.each do |t|
ActiveRecord::Base.connection.reset_pk_sequence!(t)
end
#or ActiveRecord::Base.connection.tables.each { |t| ActiveRecord::Base.connection.reset_pk_sequence!(t) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment