Skip to content

Instantly share code, notes, and snippets.

@theterminalguy
Forked from paulsturgess/reset_primary_key.md
Created January 18, 2017 13:38
Show Gist options
  • Save theterminalguy/ae61514dac5c792c64afbfa0255cbdab to your computer and use it in GitHub Desktop.
Save theterminalguy/ae61514dac5c792c64afbfa0255cbdab to your computer and use it in GitHub Desktop.
Reset postgres primary key index using Rails
$ ActiveRecord::Base.connection.reset_pk_sequence!('table_name')

If you need the table names:

$ ActiveRecord::Base.connection.tables
=> ["accounts", "assets", ...]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment