Evgeniya Smirnova
Evgeniya Smirnova

Reputation: 95

error saving data to database

I'm using Django-models for saving data to database but I have a problem, a new record has an incorrect id (I need to save some records in a for loop)

My error:

IntegrityError: (1062, u"Duplicate entry '46' for key 'PRIMARY'")

The view:

Upvotes: 3

Views: 128

Answers (1)

Druta Ruslan
Druta Ruslan

Reputation: 7402

try to put subject in for loop statment, i think you need to create new subject object every time when need to save different subjects

i in range(len(SUBJECTS)):
    subject = Subjects()
    ...
    subject.save()

Upvotes: 1

Related Questions