I have a question about deleting django DB primary_key.

Asked 2 years ago, Updated 2 years ago, 40 views

Hello,

I am currently using django and mysql in conjunction.

When db builds up, objects.all().delete() deletes the entire data and saves it again and again.

If you delete objects.all().delete(), the entire data will be deleted.

The ID(pk) numbers keep piling up, can you erase this value as well?

Delete 10 data with objects.all().delete() and enter the data again.

The id(pk) is re-entered from number 11, so I would like to ask if I can start the id value from number 1.

django mysql

2022-09-21 13:52

1 Answers

The table is really temporary, so if you can fly it like that, you can do something called TRUNCATE. https://stackoverflow.com/a/2989122

However, if id goes up from 11 just because you don't like aesthetics, (I used to do that)... We recommend that you just change your preference and stick to all().delete(). This is because the auto incremental replacement key is an index that should be used well when present. If there is a problem with data consistency later, it may be too late by then.


2022-09-21 13:52

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.