django.core.exceptions.ImproperlyConfigured: Application labels aren't unique, duplicates: admin
创建了一个Django项目,且包含一个admin的app,但是在启动Django的是时候抛出了以下异常:
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x00000180A3C34400>
Traceback (most recent call last):
File "C:\Python37\lib\site-packages\django\utils\autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "C:\Python37\lib\site-packages\django\core\management\commands\runserver.py", line 116, in inner_run
autoreload.raise_last_exception()
File "C:\Python37\lib\site-packages\django\utils\autoreload.py", line 251, in raise_last_exception
six.reraise(*_exception)
File "C:\Python37\lib\site-packages\django\utils\six.py", line 685, in reraise
raise value.with_traceback(tb)
File "C:\Python37\lib\site-packages\django\utils\autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "C:\Python37\lib\site-packages\django\__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Python37\lib\site-packages\django\apps\registry.py", line 89, in populate
"duplicates: %s" % app_config.label)
django.core.exceptions.ImproperlyConfigured: Application labels aren't unique, duplicates: admin
最后提示是:
django.core.exceptions.ImproperlyConfigured: Application labels aren't unique, duplicates: admin
说:应用程序标签不是唯一的,重复的: admin
查看配置文件:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'admin.apps.AdminConfig',
]
第一个和最后一个貌似有点重复,尝试注释掉最后一个
会发现没有数据库:
E:\Project\library>python manage.py migrate
Traceback (most recent call last):
File "C:\Python37\lib\site-packages\django\db\backends\mysql\base.py", line 26, in <module>
import MySQLdb as Database
ModuleNotFoundError: No module named 'MySQLdb'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "C:\Python37\lib\site-packages\django\core\management\__init__.py", line 364, in execute_from_command_line
utility.execute()
File "C:\Python37\lib\site-packages\django\core\management\__init__.py", line 338, in execute
django.setup()
File "C:\Python37\lib\site-packages\django\__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Python37\lib\site-packages\django\apps\registry.py", line 108, in populate
app_config.import_models()
File "C:\Python37\lib\site-packages\django\apps\config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "C:\Python37\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Python37\lib\site-packages\django\contrib\auth\models.py", line 4, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "C:\Python37\lib\site-packages\django\contrib\auth\base_user.py", line 52, in <module>
class AbstractBaseUser(models.Model):
File "C:\Python37\lib\site-packages\django\db\models\base.py", line 124, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "C:\Python37\lib\site-packages\django\db\models\base.py", line 325, in add_to_class
value.contribute_to_class(cls, name)
File "C:\Python37\lib\site-packages\django\db\models\options.py", line 214, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "C:\Python37\lib\site-packages\django\db\__init__.py", line 33, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:\Python37\lib\site-packages\django\db\utils.py", line 211, in __getitem__
backend = load_backend(db['ENGINE'])
File "C:\Python37\lib\site-packages\django\db\utils.py", line 115, in load_backend
return import_module('%s.base' % backend_name)
File "C:\Python37\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Python37\lib\site-packages\django\db\backends\mysql\base.py", line 30, in <module>
'Did you install mysqlclient or MySQL-python?' % e
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'.
Did you install mysqlclient or MySQL-python?
但是数据库的配置已经配置好了:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'library',
'HOST': '127.0.0.1',
'PORT': 3306,
'USER': 'root',
'PASSWORD': '########',
}
}
最后发现是应用名称和Django内置admin.py冲突了修改文件名就ok了
作者: 咕咚!
出处: https://www.cnblogs.com/linga/
关于作者:专注虚拟化,运维开发,RPA,Rust,Go,Python!
本文版权归作者和博客园共有,禁止*.csdn.net转载,禁止以盈利为目的的转载,转载文章,但未经作者同意必须保留此段声明,且在文章页面明显位置给出, 原文链接 如有问题, 可邮件(oldsixa@163.com)咨询.