Django manage.py - create auth_permission and django_content_type tables

I cannot use syncdb because my application uses some MySQL views. I ran manage.py sqlall <app>, but this does not display the SQL table for the django_content_type table or the auth_permission table. I also looked at the south and the evolution of django, but they both require syncdb, and I'm not sure that they will help anyway.

I manually added some models to the tables, but it becomes frustrating, and having installed the dbsettings application, I'm not sure what I need to enter now.

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

Thank.

+5
source share
3 answers

, : auth_permission Django manage.py sql django - Django.

, :

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

. :

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)

, , . interactive=True , , .

+12

@hajamie , , - , !

django = 1.9.7

from django.contrib.auth.management import create_permissions
from django.contrib.auth.models import Permission
from django.apps import apps
def fix_user_permission():
    """
    run this method via shell whenever any amendments in any of the tables is made
    """
    print "fixing user permissions"
     # delete pre-existing user permission 
    Permission.objects.all().delete()
    apps.models_module = True
    create_permissions(apps, verbosity=0)
    apps.models_module = None
    print "process completed - fixed user permissions"
+2

The simplest solution I found is to install the Django extensions , add it to settings.INSTALLED_APPS and run:

manage.py update_permissions
0
source

All Articles