-1

I am working on Django, so I created my table on my models.py. By default when I start registering data, the id, set as primary key, begins with the initial value 1 and increments each time I do a new register.

I have loaded some data in my table, so the final id right now is 185. I run the server and try to add a new register, but I get an error about id duplicity. Django is trying to save the register in id 1.

How do I get it to continue saving the register from id 186 and onwards?

I tried this on my models:

class MyModel(models.Model):
    id = models.AutoField(primary_key=True, initial=123)

but it does not recognize the kwarg initial.

philipxy
  • 14,867
  • 6
  • 39
  • 83
jose
  • 3
  • 1

1 Answers1

0

You will likely want to use sqlsequencereset.

You can run it in the terminal and it will output SQL commands for resetting the sequence on every table in the specified module.

python manage.py sqlsequencereset <your_app_label>

You can manually run any generated SQL commands, or you can pipe them into django's dbshell to run all of them automatically.

python manage.py sqlsequencereset <your_app_label> | python manage.py dbshell

See this question for more discussion on this topic.

Cowcium
  • 16
  • 3
  • thank you very much!!!!! after a week of seeking and asking everywhere, I have finally got the correct answer!!! – jose Feb 11 '23 at 19:44