Django manage.py - Creating auth_permission and django_content_type tables

hajamie picture hajamie · Jan 19, 2012 · Viewed 8.2k times · Source

I am unable to use syncdb because my app uses some MySQL views. I have run manage.py sqlall <app>, but this does not output the SQL for django_content_type table or the auth_permission tables. I have also had a look into south and django evolution, but they both require syncdb, and I'm not sure they would help anyway.

I have manually added some models to the tables, but this is getting frustrating, and having installed the dbsettings app I am unsure of what I now need to enter.

Does anyone know of a way to get manage.py (or something else) to output the SQL for these tables and their contents?

Thanks.

Answer

hajamie picture hajamie · Jan 20, 2012

Having done a bit more digging, I found these: Fixing the auth_permission table after renaming a model in Django and manage.py sql command for django models - Django.

These output the tables, but not the data:

python manage.py sql auth
python manage.py sql admin

But this gets a lot closer. In the end I managed it with the following:

from django.contrib.auth.management import create_permissions
from django.db.models import get_apps
for app in get_apps():
    create_permissions(app, None, 2)

from django.contrib.contenttypes.management import update_all_contenttypes
update_all_contenttypes(interactive=True)

This adds all the permissions and then all the content types which are needed. interactive=True means that it asks you if you want to remove stale content types.