0

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 ?

lmatejic
  • 71
  • 10
  • Did you filled the database using a seed.rb task? – MurifoX Aug 13 '15 at 11:42
  • Not too relevant, let's say that I didn't use seed.rb and I just want to make the IDs go back to 1 and delete all entered data for only a **part** of the DB. It seems to me that that's not manageable but still, worth a shot to ask. – lmatejic Aug 13 '15 at 11:45

1 Answers1

1

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?

Community
  • 1
  • 1
smallbutton
  • 3,377
  • 15
  • 27
  • Hmm, I wrote a helper method to use in my view as a kind of 'Reset' button but the DB seems to disagree with the syntax. I'll have to look into the DB commands some more. But this seems like something I wanted to do, thanks. – lmatejic Aug 13 '15 at 11:56