Updating Django to Postgresql with bad auth.perms

To get rid of user permissions based on tables that no longer exist, use:

python manage.py remove_stale_contenttypes

However, you may have a different error:

django.core.serializers.base.DeserializationError: Permission matching query does not exist.: (auth.user:pk=<integer>) field_value was '['add_field_name', 'app_name', 'model_name']'

To get rid of an old permission that should not exist, on a table that SHOULD exist, you’re going to have to do a bit more.

python manage.py shell
from django.contrib.contenttypes.models import ContentType
from django.apps import apps
Permission = apps.get_model('auth.Permission') ## Potentially this could be just an import, but I'm entirely unsure, and this worked.
ContentType = apps.get_model('contenttypes.ContentType')
content_type = ContentType.objects.get(model="your_model_name", app_label="your_app_name")
p = Permission.objects.filter(content_type=content_type, codename="view|change|add|delete_your_field_name")
python manage.py shell
from django.contrib.contenttypes.models import ContentType
from django.apps import apps
Permission = apps.get_model('auth.Permission') ## Potentially this could be just an import, but I'm entirely unsure, and this worked.
ContentType = apps.get_model('contenttypes.ContentType')
content_type = ContentType.objects.get(model="model_name", app_label="app_name")
p = Permission.objects.filter(content_type=content_type, codename="view|change|add|delete_field_name")
p.delete() # If you're feeling very brave, you can do those two at once.

You then probably want:

python manage.py dumpdata --exclude auth.permission --exclude contenttypes --natural-foreign --indent=4 > data.json

and

python manage.py loaddata data.json --database=new_db_name


Sources: https://django.how/basics/dump-and-load-data-django/ and https://django.how/basics/dump-and-load-data-django/ – thank you both.