2016-07-25 118 views
0

我在我的項目django.contrib.auth應用程序中使用自定義應用程序和身份驗證後端替換,但仍使用原始應用程序中的某些函數/類(如_user_has_perm,_user_has_module_perms等)。禁用django.contrib.auth應用程序的遷移

的問題是,如果我不把INSTALLED_APPS我django.contrib.auth得到這樣的警告: RemovedInDjango19Warning: Model class django.contrib.auth.models.User doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.

但如果我把它放在INSTALLED_APPS,旁邊遷移創建我與替換我的表自定義模型。

那麼,如何禁用django.contrib.auth遷移?

+0

您是否想要防止僅創建用戶表或所有表被創建? – knbk

+0

我想阻止創建表auth_group,auth_permission,auth_group_permissions和django_content_type。沒有創建auth_user表.. – Alex

回答

0

如果您使用自定義用戶模型,則需要在settings.AUTH_USER_MODEL中指定它;這會阻止Django加載默認模型。

+0

我做到了。我的自定義應用名爲'cauth'。在settings.py中我有這樣一行:'AUTH_USER_MODEL ='cauth.User''。這是我的'進口從django.contrib.auth進口get_user_model auth.get_backends 從django.contrib.auth.models從django.contrib.auth進口註銷進口(_user_has_perm,_user_has_module_perms, _user_get_all_permissions) 作爲django_logout 從Django中。 contrib.auth.decorators import login_required ' – Alex

相關問題