報錯信息:
/home/python/PycharmProjects/dailyfresh/apps/user/models.py:8: RemovedInDjango19Warning: Model class apps.user.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.
- 報錯解析:apps.user.models 沒有聲明
原因:當時創建項目時為了簡化注冊app的寫法,所以在setting中加入了apps的路徑
sys.path.insert(0, os.path.join(BASE_DIR,'apps'))
然后注冊app時就不用apps.
INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'tinymce', 'cart', 'goods', 'order', 'user', )
但是當在user.views導入user.models時直接導入
from user.models import User
按這樣導入pycharm會有紅色波浪線提示,所以又改回原始寫法
from apps.user.models import User
這樣開啟服務器后就會出現上面的報錯
這樣就會導致Django注冊時app為user,但導入使用時是apps.user,所以Django沒有找到對應聲明的app所以報錯
- 解決方法:
方法1.忽略pycharm報錯,還是直接導入
from user.models import User
方法2:注冊app時不簡化寫法時用apps.注冊