Home > Software design >  Unable to Create/Edit/Delete objects on Django Admin - Foreign Key Constraint Failed
Unable to Create/Edit/Delete objects on Django Admin - Foreign Key Constraint Failed

Time:04-06

Encountering some weird behavior developing a django app. I'm using sqlite3 locally and on production at the moment. Locally the admin interface allows me to create/edit/delete objects as expected. In production, cloned from the exact same repo of code I am getting IntegrityError, Foreign Key constraint failed errors when attempting to create, edit, or delete objects.

I have a CustomUser model that I use as AUTH_USER_MODEL. Users can sign up for the service without problem locally and on production, thereby creating a CustomUser object for themselves. The strange thing is on production I cannot go about creating a user using the django admin interface without encountering the aforementioned error.

I thought maybe the issue was related to my use of a CustomUser model as AUTH USER MODEL, however even attempting to create/edit/delete other objects I encounter the same error.

I'm not sure how to go about debugging this. Any help would be greatly appreciated!

Exception Type: IntegrityError at /admin/coreapp/coreappobject/add/
Exception Value: FOREIGN KEY constraint failed

CodePudding user response:

https://code.djangoproject.com/ticket/23297

This solved my issue. It seems the foreign key constraint was resulting from a reference to the previous user model, before migrating to my custom user model midway through development.

  • Related