How to solve primary key error in django?

96 views
Skip to first unread message

Prashanth chaduvala

unread,
Jan 5, 2023, 5:08:03 AM1/5/23
to django-res...@googlegroups.com
I'm using MySQL database in django when I am creating

Id=models.AutoField(primary_key=True)

It's showing below error.
IMG-20230105-WA0003.jpg

Rodrigo Zayit

unread,
Jan 5, 2023, 9:46:23 AM1/5/23
to django-res...@googlegroups.com
It is not a primary key error. you are trying to pass 0 when inserting.
This field that Django creates is an integer auto increment field. So you don't have to set it when you want to save a new record. And you do not need to declare it in your models too... let django do it for you.

If you need more help, share your code with us.

Att.,
Rodrigo Zayit


--
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-fram...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-rest-framework/CAH5_3zkFwXDM7Dfjgnpx8r5vhW%2BCGLEvzSoMrLO5tb84RqXquQ%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages