我已经使用Python V3.6和Django 2.1创建了一个示例应用程序,并且我正在使用MySQL作为数据库。经过长时间的努力,我已经成功集成了MySQL,但是现在当我尝试为我的应用程序创建SuperUser时,它将抛出错误
(django_dev) C:\Users\******\Desktop\django_projects\shield>python manage.py mig
rate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, server_status, sessions
Running migrations:
Applying server_status.0001_initial... OK
Traceback (most recent call last):
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\dja
ngo\db\backends\utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\dja
ngo\db\backends\mysql\base.py", line 71, in execute
return self.cursor.execute(query, args)
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\MyS
QLdb\cursors.py", line 250, in execute
self.errorhandler(self, exc, value)
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\MyS
QLdb\connections.py", line 50, in defaulterrorhandler
raise errorvalue
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\MyS
QLdb\cursors.py", line 247, in execute
res = self._query(query)
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\MyS
QLdb\cursors.py", line 411, in _query
rowcount = self._do_query(q)
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\MyS
QLdb\cursors.py", line 374, in _do_query
db.query(q)
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\MyS
QLdb\connections.py", line 277, in query
_mysql.connection.query(self, query)
_mysql_exceptions.ProgrammingError: (1146, "Table 'shield_dev.django_content_typ
e' doesn't exist")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\dja
ngo\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\dja
ngo\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\dja
ngo\core\management\base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\dja
ngo\core\management\base.py", line 353, in execute
output = self.handle(*args, **options)
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\dja
ngo\core\management\base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\dja
ngo\core\management\commands\migrate.py", line 226, in handle
self.verbosity, self.interactive, connection.alias, apps=post_migrate_apps,
plan=plan,
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\dja
ngo\core\management\sql.py", line 51, in emit_post_migrate_signal
**kwargs
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\dja
ngo\dispatch\dispatcher.py", line 175, in send
for receiver in self._live_receivers(sender)
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\dja
ngo\dispatch\dispatcher.py", line 175, in <listcomp>
for receiver in self._live_receivers(sender)
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\dja
ngo\contrib\auth\management\__init__.py", line 59, in create_permissions
ctype = ContentType.objects.db_manager(using).get_for_model(klass)
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\dja
ngo\contrib\contenttypes\models.py", line 51, in get_for_model
ct = self.get(app_label=opts.app_label, model=opts.model_name)
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\dja
ngo\db\models\manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\dja
ngo\db\models\query.py", line 393, in get
num = len(clone)
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\dja
ngo\db\models\query.py", line 250, in __len__
self._fetch_all()
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\dja
ngo\db\models\query.py", line 1183, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\dja
ngo\db\models\query.py", line 54, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=
self.chunk_size)
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\dja
ngo\db\models\sql\compiler.py", line 1061, in execute_sql
cursor.execute(sql, params)
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\dja
ngo\db\backends\utils.py", line 100, in execute
return super().execute(sql, params)
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\dja
ngo\db\backends\utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._e
xecute)
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\dja
ngo\db\backends\utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\dja
ngo\db\backends\utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\dja
ngo\db\utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\dja
ngo\db\backends\utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\dja
ngo\db\backends\mysql\base.py", line 71, in execute
return self.cursor.execute(query, args)
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\MyS
QLdb\cursors.py", line 250, in execute
self.errorhandler(self, exc, value)
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\MyS
QLdb\connections.py", line 50, in defaulterrorhandler
raise errorvalue
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\MyS
QLdb\cursors.py", line 247, in execute
res = self._query(query)
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\MyS
QLdb\cursors.py", line 411, in _query
rowcount = self._do_query(q)
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\MyS
QLdb\cursors.py", line 374, in _do_query
db.query(q)
File "C:\Users\ccduce\AppData\Local\Continuum\miniconda3\lib\site-packages\MyS
QLdb\connections.py", line 277, in query
_mysql.connection.query(self, query)
django.db.utils.ProgrammingError: (1146, "Table 'shield_dev.django_content_type'
doesn't exist")
If you suspect this is an IPython bug, please report it at:
https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev@python.org
You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.
Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
如果我使用默认数据库SqLite3,一切都可以正常工作,但是当我尝试使用MySQL时,我发现了错误。
这里是我的setting.py供您参考。
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'polls',
]
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'shield_dev',
'USER': '*****',
'PASSWORD': '****',
'HOST': '******',
'PORT': '3306',
'OPTIONS': {
'sql_mode': 'traditional',
}
}
}