Skip to content

Instantly share code, notes, and snippets.

@paulsturgess
Created February 27, 2013 19:49
Show Gist options
  • Save paulsturgess/5051080 to your computer and use it in GitHub Desktop.
Save paulsturgess/5051080 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", ...]
@tasdendu
Copy link

This is it. Perfect answer.

@kinoute
Copy link

kinoute commented Jun 7, 2020

2020, still great. thanks!

@Mozart2234
Copy link

2020, still great. thanks!

Yep!!

@Rukosenpa
Copy link

2021, here for get help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment