Django makemigrations 和迁移

py manage.py makemigrations [project_name]我在使用and命令时遇到问题py manage.py migrate。每次我以正确的顺序尝试这两个命令时,都会收到以下错误:


Traceback (most recent call last):

  File "C:\Users\Gilbert\PycharmProjects\GGprojects\django\manage.py", line 20, in <module>

    main()

  File "C:\Users\Gilbert\PycharmProjects\GGprojects\django\manage.py", line 17, in main

    execute_from_command_line(sys.argv)

  File "C:\Users\Gilbert\PycharmProjects\GGprojects\django\ll_env\lib\site-packages\django\core\management\__init__.py", line 371, in execute_from_command_line

    utility.execute()

  File "C:\Users\Gilbert\PycharmProjects\GGprojects\django\ll_env\lib\site-packages\django\core\management\__init__.py", line 365, in execute

    self.fetch_command(subcommand).run_from_argv(self.argv)

  File "C:\Users\Gilbert\PycharmProjects\GGprojects\django\ll_env\lib\site-packages\django\core\management\base.py", line 301, in run_from_argv

    connections.close_all()

  File "C:\Users\Gilbert\PycharmProjects\GGprojects\django\ll_env\lib\site-packages\django\db\utils.py", line 225, in close_all

    connection.close()

  File "C:\Users\Gilbert\PycharmProjects\GGprojects\django\ll_env\lib\site-packages\django\db\backends\sqlite3\base.py", line 190, in close

    if not self.is_in_memory_db():

  File "C:\Users\Gilbert\PycharmProjects\GGprojects\django\ll_env\lib\site-packages\django\db\backends\sqlite3\base.py", line 287, in is_in_memory_db

    return self.creation.is_in_memory_db(self.settings_dict['NAME'])

  File "C:\Users\Gilbert\PycharmProjects\GGprojects\django\ll_env\lib\site-packages\django\db\backends\sqlite3\creation.py", line 13, in is_in_memory_db

    return database_name == ':memory:' or 'mode=memory' in database_name

TypeError: argument of type 'WindowsPath' is not iterable

查看错误,我会说我的 Python 路径可能不正确。它的当前路径是C:\Users\Gilbert\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python 3.9. 这是出现错误的原因吗?它会影响我的 Django 项目吗?另外,我该如何解决这个问题?


素胚勾勒不出你
浏览 79回答 1
1回答

MYYA

看起来它没有获取数据库路径。检查 settings.py 文件中的数据库名称。例如:对于 sqlite3,它应该是这样的:DATABASES = {&nbsp; &nbsp; 'default': {&nbsp; &nbsp; 'ENGINE': 'django.db.backends.sqlite3',&nbsp; &nbsp; 'NAME': str(os.path.join(BASE_DIR, "db.sqlite3"))&nbsp; &nbsp;}&nbsp;}如果这不适合您,请在此处分享您的数据库设置,以便我可以提供帮助
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python