Autofield that is always continuous

This is my first time in Django and databases in general. I need a field that increments by itself like the models.AutoField but its value in all records should be continuous starting from 1. Even if one of the older records is deleted, all of the newer ones should be adjusted to make the AutoField continuous. How do I do that?

In the general case, this is a really bad idea to try and do this. As a concept it doesn’t scale, and would be a performance killer for your database.

My first reaction is that this may be an example of an XY Problem.

So my follow-up question would be to ask why do you think this is necessary? What benefits would you hope to achieve from this? (There may be a better way to handle it, depending upon what the underlying requirement really is.)

I have this Row model:

And in the Django admin panel, I want each row to be named Row.SNO (and not just ‘Row’ as seen in the screenshot), where SNO is a field as I described in the post. The default is not what I am looking for as it won’t be continuous starting at ‘1’ for all the Rows.

It might be an XY Problem, and could be solved within the admin panel without altering the database. What I am saying is I don’t need the SNO field as long as I can see the rows appearing with the desired names.

This is basically repeating Ken’s question, but why do you want the numbers to be continuous when viewing the list in Django Admin?

It’s not a must, just makes things more convenient.

How does it make things more “convenient”? It tends to make things more confusing by showing numbers with no direct relationship to the objects being displayed.

If I have a list of four people, “Alice”, “Bob”, “Charlie”, “David”; and I’m looking at this list regularly, I’m going to see the number 4 associated with David. I might even make some notes or copy some data elsewhere using “4” as a shorthand indicator for “David”.

If “Bob” is removed, “David” is now “3”, and all my notes and external references are no longer valid. Just as bad, “David” as “3” is now a reference to everything I collected about “Charlie”.