0

When a new user is registered through the registration form of Laravel framework, the id given to this new user is not the next id that exists in table users.

To give you an example, take a look to the next picture:

enter image description here

The id of the new registered user should be 6, and not 22.

What I assume is that for testing purposes I already have deleted some users from table users and that maybe the reason of the gap of ids.

Any ideas how to fix this?

Tinxuanna
  • 206
  • 1
  • 3
  • 16
  • When you saying testing, do you mean you've manually created users and deleted them, or you've written unit/feature tests? – Rwd Dec 09 '21 at 09:19
  • @Rwd I have manually created users and deleted them, without using the Laravel registration method. – Tinxuanna Dec 09 '21 at 09:21
  • 1
    https://stackoverflow.com/questions/8923114/how-to-reset-auto-increment-in-mysql – Rwd Dec 09 '21 at 09:21
  • @Rwd It worked, your answer helped me. I used the sql command 'truncate table users;' and thus the auto-increment id was reseted. Then, through the registration form, new users get correct sequent ids. I have to mention that through the 'truncate' command all data from table users were deleted. So, please take a backup before. – Tinxuanna Dec 09 '21 at 10:03

1 Answers1

1

Ids will not get reused, id column is using auto_increment by default

1 - user 1
2 - deleted
3 - deleted
4 - new user // new user will get id 4 not 2

if you manually delete users when doing your tests you should reset auto_increment

example with phpmyadmin

enter image description here

there is a AUTO_INCREMENT field you need to reset to the value you want

Lk77
  • 2,203
  • 1
  • 10
  • 15