Skip to content

Instantly share code, notes, and snippets.

@Ivor
Last active December 14, 2015 06:59
Show Gist options
  • Save Ivor/5046702 to your computer and use it in GitHub Desktop.
Save Ivor/5046702 to your computer and use it in GitHub Desktop.
PG duplicate key issue after importing pg dump.
#If you get this issue when trying to save to a recently imported postgres db.
#PG::Error: ERROR: duplicate key value violates unique constraint
#Run the following in your rails console.
ActiveRecord::Base.connection.tables.each do |t|
ActiveRecord::Base.connection.reset_pk_sequence!(t)
end;nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment