Skip to content
Advertisement

psycopg2.IntegrityError: duplicate key value violates unique constraint DETAIL: Key (id)=(19) already exists

I am not setting the primary key manually. How could this be happening?

JavaScript

In my 5 years of programming in Django I’ve never gotten this error. I can’t tell what is going wrong by just looking at my code and the traceback. What could be wrong? Let me know if I need to post more code. Thanks in advance. Any help is appreciated.

Advertisement

Answer

You are trying to save your submodel in your save method.

JavaScript

Therefore you are saving your model before calling super’s save method. You should set your image but not save it before calling super’s save method.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement