Last active
May 23, 2018 04:01
-
-
Save leemour/b855947f38ce8784dd769a4aeba2a317 to your computer and use it in GitHub Desktop.
Reset Postgres primary key sequence from Rails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
start_id = Product.maximum(:id) + 1 | |
table = :products | |
ApplicationRecord.connection.execute("ALTER SEQUENCE #{table}_id_seq RESTART WITH #{start_id}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment