Migration auth.0011_update_proxy_permissions from Django 2.2 fails to apply

341 views
Skip to first unread message

Julien Enselme

unread,
Apr 4, 2019, 7:08:04 AM4/4/19
to Django users
Hi,

I am trying to update my project to Django 2.2 (we are currently on 2.0.13). When I launch `python manage.py migrate`, I get this error message when migration auth.0011_update_proxy_permissions is applying (full stacktrace is available here):
django.db.utils.IntegrityError: duplicate key value violates unique constraint "idx_18141_auth_permission_content_type_id_01ab375a_uniq"
DETAIL:  Key (content_type_id, codename)=(12, add_agency) already exists.

It looks like the migration is trying to re-create already existing entries in the auth_permission table. At first I though it cloud because we recently renamed a model. But after digging and deleting the entries associated with the renamed model from our database in the auth_permission table, the problem still occurs with other proxy models.

I search for a ticket about this on the bug tracker but found nothing.

Can someone help me on this? I guess I can keep deleting problematic entries from our database one by one but it will take a long time and it doesn't look right.

Regards,
Julien Enselme

אורי

unread,
Apr 5, 2019, 11:02:52 AM4/5/19
to django...@googlegroups.com
Hi Julien,

Sounds like a bug in Django 2.2. Try to report it on https://code.djangoproject.com/ and/or by email to django-d...@googlegroups.com .

In which table the exception occurs?

Did you try to upgrade to Django 2.1 and then to 2.2?


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/03432e49-935f-4735-894b-2e150eac4899%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

אורי

unread,
Apr 5, 2019, 11:06:13 AM4/5/19
to django...@googlegroups.com
Hi Julien,

Also, try to install a new - either local or remote - environment with your code and then try to upgrade Django there. There might be a problem specific with this deployment. This exception, on which environment did you receive it? Local or remote?


On Thu, Apr 4, 2019 at 2:07 PM Julien Enselme <julien....@bureauxlocaux.com> wrote:
--

Arpit Singh

unread,
Apr 8, 2019, 7:24:00 AM4/8/19
to Django users
Hi Julien,

We faced a similar issue, thought it's probably a bug in Django but realised that our unique setup of multiple databases is the reason we are facing this issue unlike many others (except you ofcourse)
It turned out that this data integrity issue will pop up if you run this migration file more than once.
.
So the thing to keep in mind is that a datamigration files (0011_update_proxy_permissions is a datamigration file) isn't associated with any django model, so a faulty router might make it run on all databases.
We hadn't thought of this scenario in our custom django router either.
Once we fixed our django router to run only on our target database in case of a migration file, this problem was resolved.

For now, forward migrations in auth app are working fine. Reverse migrations are still broken though (something to do with apps.get_models() returning inconsistent results, but that's a problem for another day) 

P.S: It would have helped if Django had provided routers with proper hints though. (https://docs.djangoproject.com/en/2.2/howto/writing-migrations/#data-migrations-and-multiple-databases)

Julien Enselme

unread,
Apr 9, 2019, 6:38:29 AM4/9/19
to django...@googlegroups.com
@Arpit Singh: I am in a single database setup and we don't use database routers. As far as I know, the migration was never applied before. But from what I understand from you answer, I can --fake it and I should be fine.

@אורי רודברג I tried to update directly from 2.0 to 2.2. Since we switched to 2.1, I just retried to update  to 2.2 and I hit the same issue. The error occurs in the auth_permission table.

> Also, try to install a new - either local or remote - environment with your code and then try to upgrade Django there. There might be a problem specific with this deployment. This exception, on which environment did you receive it? Local or remote?

I happened in my local env. I tried to delete the venv and recreate it from scratch but it didn't help.

I'll try to report the bug.

Thanks for you help!

Julien Enselme
Développeur chez BureauxLocaux


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

abhinav

unread,
Jun 2, 2021, 7:41:47 AM6/2/21
to Django users
Hi,
@julien  i also encountered this issue did you get a fix for the issue

Reply all
Reply to author
Forward
0 new messages