Search code examples
ruby-on-railsrubydatabasepostgresql

How to restart id counting on a table in PostgreSQL after deleting some previous data?


I'm using PostgreSQL database on Rails 2.3.8 and I need to restart auto increment ID on my table. How can I do that?


Solution

  • You can do it directly in PostgreSQL using "alter sequence": http://www.postgresql.org/docs/current/static/sql-altersequence.html

    Particularly "restart with"

    I don't know how you would do it via the rails abstraction.