我把思念作箋,隨風(fēng)而去,落在你常路過的那個街角…
錯誤復(fù)現(xiàn)
PS D:\教學(xué)文件\Django\djangoProject\webDemo02> python manage.py createsuperuser
System check identified some issues:
WARNINGS:
?: (urls.W005) URL namespace 'admin' isn't unique. You may not be able to reverse all URLs in this namespace
You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
Traceback (most recent call last):
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\backends\utils.py", line 89, in _execute
return self.cursor.execute(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\backends\sqlite3\base.py", line 328, in execute
return super().execute(query, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sqlite3.OperationalError: no such table: auth_user
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "D:\教學(xué)文件\Django\djangoProject\webDemo02\manage.py", line 22, in <module>
main()
File "D:\教學(xué)文件\Django\djangoProject\webDemo02\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\core\management\__init__.py", line 442, in execute_from_command_line
utility.execute()
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\core\management\__init__.py", line 436, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\core\management\base.py", line 412, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 88, in execute
return super().execute(*args, **options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\core\management\base.py", line 458, in execute
output = self.handle(*args, **options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 109, in handle
default_username = get_default_username(database=database)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\contrib\auth\management\__init__.py", line 168, in get_default_username
auth_app.User._default_manager.db_manager(database).get(
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\models\manager.py", line 87, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\models\query.py", line 633, in get
num = len(clone)
^^^^^^^^^^
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\models\query.py", line 380, in __len__
self._fetch_all()
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\models\query.py", line 1881, in _fetch_all
self._result_cache = list(self._iterable_class(self))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\models\query.py", line 91, in __iter__
results = compiler.execute_sql(
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\models\sql\compiler.py", line 1562, in execute_sql
cursor.execute(sql, params)
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\backends\utils.py", line 102, in execute
return super().execute(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\backends\utils.py", line 67, in execute
return self._execute_with_wrappers(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\backends\utils.py", line 80, in _execute_with_wrappers
return executor(sql, params, many, context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
with self.db.wrap_database_errors:
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\utils.py", line 91, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\backends\utils.py", line 89, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\backends\sqlite3\base.py", line 328, in execute
return super().execute(query, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django.db.utils.OperationalError: no such table: auth_user
錯誤解析
這個錯誤消息表明Django在執(zhí)行python manage.py createsuperuser
命令時無法找到auth_user
表,通常是因?yàn)閿?shù)據(jù)庫尚未初始化或者數(shù)據(jù)庫遷移(migrations)尚未完成。要解決這個問題,您可以按照以下步驟操作:
-
確保您已經(jīng)在項(xiàng)目目錄中運(yùn)行了以下命令以應(yīng)用數(shù)據(jù)庫遷移:
python manage.py makemigrations python manage.py migrate
這將創(chuàng)建數(shù)據(jù)庫表并將其初始化,包括
auth_user
表。 -
如果您之前已經(jīng)執(zhí)行了上述命令,但仍然遇到問題,可能是數(shù)據(jù)庫出現(xiàn)了一些問題。您可以嘗試刪除數(shù)據(jù)庫并重新創(chuàng)建它,然后再次運(yùn)行遷移命令:
rm db.sqlite3 # 刪除數(shù)據(jù)庫文件 python manage.py makemigrations python manage.py migrate
-
如果您在項(xiàng)目中使用的是不同的數(shù)據(jù)庫引擎(例如MySQL或PostgreSQL),請確保數(shù)據(jù)庫服務(wù)器正在運(yùn)行,并且數(shù)據(jù)庫配置正確。
-
如果您使用的是SQLite數(shù)據(jù)庫,確保您有寫入數(shù)據(jù)庫文件的權(quán)限,因?yàn)橛袝r權(quán)限問題可能導(dǎo)致無法創(chuàng)建數(shù)據(jù)庫表。
按照這些步驟之一,您應(yīng)該能夠成功執(zhí)行python manage.py createsuperuser
命令并創(chuàng)建超級用戶。文章來源:http://www.zghlxwxcb.cn/news/detail-734003.html
文章來源地址http://www.zghlxwxcb.cn/news/detail-734003.html
到了這里,關(guān)于python manage.py createsuperuser運(yùn)行錯誤的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!