$ ActiveRecord::Base.connection.reset_pk_sequence!('table_name')
If you need the table names:
$ ActiveRecord::Base.connection.tables
=> ["accounts", "assets", ...]
$ ActiveRecord::Base.connection.reset_pk_sequence!('table_name')
If you need the table names:
$ ActiveRecord::Base.connection.tables
=> ["accounts", "assets", ...]
Combine both of them:
ActiveRecord::Base.connection.tables.each do |t|
ActiveRecord::Base.connection.reset_pk_sequence!(t)
end
This is it. Perfect answer.
2020, still great. thanks!
2020, still great. thanks!
Yep!!
2021, here for get help
It's been 5 years and this is still useful. Thanks! 🥇