{"id":712,"date":"2024-03-13T17:11:01","date_gmt":"2024-03-13T17:11:01","guid":{"rendered":"https:\/\/watchdiana.fail\/blog\/?p=712"},"modified":"2024-03-13T19:09:30","modified_gmt":"2024-03-13T19:09:30","slug":"updating-django-to-postgresql-with-bad-auth-perms","status":"publish","type":"post","link":"https:\/\/watchdiana.fail\/blog\/2024\/03\/13\/updating-django-to-postgresql-with-bad-auth-perms\/","title":{"rendered":"Updating Django to Postgresql with bad auth.perms"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">To get rid of user permissions based on tables that no longer exist, use:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>python manage.py remove_stale_contenttypes<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, you may have a different error:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>django.core.serializers.base.DeserializationError: Permission matching query does not exist.: (auth.user:pk=&lt;integer&gt;) field_value was '['add_field_name', 'app_name', 'model_name']'<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To get rid of an old permission that should not exist, on a table that SHOULD exist, you&#8217;re going to have to do a bit more.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>python manage.py shell<br>from django.contrib.contenttypes.models import ContentType<br>from django.apps import apps<br>Permission = apps.get_model('auth.Permission')  ## Potentially this could be just an import, but I'm entirely unsure, and this worked.<br>ContentType = apps.get_model('contenttypes.ContentType')<br>content_type = ContentType.objects.get(model=\"your_model_name\", app_label=\"your_app_name\")<br>p = Permission.objects.filter(content_type=content_type, codename=\"view|change|add|delete_your_field_name\")<br>python manage.py shell<br>from django.contrib.contenttypes.models import ContentType<br>from django.apps import apps<br>Permission = apps.get_model('auth.Permission')  ## Potentially this could be just an import, but I'm entirely unsure, and this worked.<br>ContentType = apps.get_model('contenttypes.ContentType')<br>content_type = ContentType.objects.get(model=\"model_name\", app_label=\"app_name\")<br>p = Permission.objects.filter(content_type=content_type, codename=\"view|change|add|delete_field_name\")<br>p.delete() # If you're feeling very brave, you can do those two at once.<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You then probably want:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>python manage.py dumpdata --exclude auth.permission --exclude contenttypes --natural-foreign --indent=4 &gt; data.json<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">and<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>python manage.py loaddata data.json --database=new_db_name<\/code><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\">Sources: https:\/\/django.how\/basics\/dump-and-load-data-django\/ and https:\/\/django.how\/basics\/dump-and-load-data-django\/ &#8211; thank you both.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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=&lt;integer&gt;) field_value was &#8216;[&#8216;add_field_name&#8217;, &#8216;app_name&#8217;, &#8216;model_name&#8217;]&#8217; To get rid of an old permission that should not exist, on a table that SHOULD exist, you&#8217;re [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[9,104,105,107,13],"class_list":["post-712","post","type-post","status-publish","format-standard","hentry","category-life","tag-coding","tag-fun-with-django","tag-fun-with-python","tag-fun-with-sql","tag-things-i-do-because-im-stubborn","missing-thumbnail"],"_links":{"self":[{"href":"https:\/\/watchdiana.fail\/blog\/wp-json\/wp\/v2\/posts\/712","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/watchdiana.fail\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/watchdiana.fail\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/watchdiana.fail\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/watchdiana.fail\/blog\/wp-json\/wp\/v2\/comments?post=712"}],"version-history":[{"count":3,"href":"https:\/\/watchdiana.fail\/blog\/wp-json\/wp\/v2\/posts\/712\/revisions"}],"predecessor-version":[{"id":717,"href":"https:\/\/watchdiana.fail\/blog\/wp-json\/wp\/v2\/posts\/712\/revisions\/717"}],"wp:attachment":[{"href":"https:\/\/watchdiana.fail\/blog\/wp-json\/wp\/v2\/media?parent=712"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/watchdiana.fail\/blog\/wp-json\/wp\/v2\/categories?post=712"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/watchdiana.fail\/blog\/wp-json\/wp\/v2\/tags?post=712"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}