为了账号安全,请及时绑定邮箱和手机立即绑定

Django makemigrations 和迁移

Django makemigrations 和迁移

素胚勾勒不出你 2024-01-15 21:35:35
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_nameTypeError: argument of type 'WindowsPath' is not iterable查看错误,我会说我的 Python 路径可能不正确。它的当前路径是C:\Users\Gilbert\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python 3.9. 这是出现错误的原因吗?它会影响我的 Django 项目吗?另外,我该如何解决这个问题?
查看完整描述

1 回答

?
MYYA

TA贡献1868条经验 获得超4个赞

看起来它没有获取数据库路径。检查 settings.py 文件中的数据库名称。


例如:对于 sqlite3,它应该是这样的:


DATABASES = {

    'default': {

    'ENGINE': 'django.db.backends.sqlite3',

    'NAME': str(os.path.join(BASE_DIR, "db.sqlite3"))

   }

 }

如果这不适合您,请在此处分享您的数据库设置,以便我可以提供帮助


查看完整回答
反对 回复 2024-01-15
  • 1 回答
  • 0 关注
  • 78 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信