简体   繁体   中英

Is there a way to reset only a part of the DB in Rails?

I was wondering if it's possible to reset just a part of the DB to free up the IDs that were taken by previous entries. For example, let's say your DB is filled with info about users and about admins . Then I'd like to delete all admins or users and get back to filling the DB up back from ID 1 depending on which ones I've removed. Is this even possible without doing rake db:reset and resetting the whole DB ?

Just delete the records first. Then you have to look for the DBspecific command that resets the autoincrement counter. This post shows how to do that (they do it in a migration although I think the rails console would work as well:

How to reset auto increment field in a ActiveRecord migration?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM