gpt4 book ai didi

python - 在Django项目中获取TypeError错误

转载 作者:行者123 更新时间:2023-12-03 07:45:26 27 4
gpt4 key购买 nike

我为新项目创建了虚拟环境,安装了django并启动了新项目。但是,每当我使用manage.py运行一行代码时,都会出现此长错误。

PS D:\My stuff\Website development\Isow website\isow> python manage.py makemigrations
No changes detected
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\rahma\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\rahma\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\rahma\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\base.py", line 336, in run_from_argv
connections.close_all()
File "C:\Users\rahma\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\utils.py", line 224, in close_all
connection.close()
File "C:\Users\rahma\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\sqlite3\base.py", line 248, in close
if not self.is_in_memory_db():
File "C:\Users\rahma\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\sqlite3\base.py", line 367, in is_in_memory_db
return self.creation.is_in_memory_db(self.settings_dict['NAME'])
File "C:\Users\rahma\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\sqlite3\creation.py", line 12, in is_in_memory_db
return database_name == ':memory:' or 'mode=memory' in database_name
TypeError: argument of type 'WindowsPath' is not iterable
数据库条目:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}

最佳答案

似乎NAME已转换为pathlib.Path(WindowsPath)对象而不是字符串,该对象随后无法以os.path期望字符串的相同方式在Django中使用(不确定100%,因为未深入调查)
因此以字符串形式转换将是适当的

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

关于python - 在Django项目中获取TypeError错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63447011/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com