Skip to content

Instantly share code, notes, and snippets.

@leemour
Last active May 23, 2018 04:01
Show Gist options
  • Save leemour/b855947f38ce8784dd769a4aeba2a317 to your computer and use it in GitHub Desktop.
Save leemour/b855947f38ce8784dd769a4aeba2a317 to your computer and use it in GitHub Desktop.
Reset Postgres primary key sequence from Rails
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