Sometimes when saving an object in Django, one faces the following kind of errors:

  File "/home/alan/virtualenv_1/lib/python2.6/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
IntegrityError: (1062, "Duplicate entry '18' for key 'PRIMARY'")
 

To solve such error, the easiest way is often to just delete the object that was previously stored, with the following command:

 TextModification.objects.filter(id=18).delete()
 

In this example, the object that I want to create belongs to the class TextModification.


Leave a Reply

Your email address will not be published. Required fields are marked *