Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在django项目中获取typeError错误_Python_Django_Error Handling_Typeerror - Fatal编程技术网

Python 在django项目中获取typeError错误

Python 在django项目中获取typeError错误,python,django,error-handling,typeerror,Python,Django,Error Handling,Typeerror,我为我的新项目创建了一个虚拟环境,安装了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 2

我为我的新项目创建了一个虚拟环境,安装了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

似乎名称正在被转换为pathlib.Path()对象,而不是字符串,因此无法在Django中以与预期字符串相同的方式使用该字符串(由于没有深入调查,所以不能100%确定)

所以用线来浇铸是合适的

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

似乎名称正在被转换为pathlib.Path()对象,而不是字符串,因此无法在Django中以与预期字符串相同的方式使用该字符串(由于没有深入调查,所以不能100%确定)

所以用线来浇铸是合适的

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

确保确实在venv中执行命令(您应该看到
(venv)

如果你像@iklinac所说的那样,这将解决你的问题:

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

确保确实在venv中执行命令(您应该看到
(venv)

如果你像@iklinac所说的那样,这将解决你的问题:

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

您的数据库相关设置是什么样子的?@deceze抱歉,我不明白您的
设置.py
数据库
条目是什么样子的?@deceze我编辑了我的帖子,并在我的设置中添加了数据库条目。py你能试试字符串转换名path str(os.path.join(BASE_DIR,“db.sqlite3”))你的数据库相关设置是什么样子的吗?@deceze抱歉,我不明白你的
设置.py是什么意思;
DATABASES
条目是什么样子的?@deceze我编辑了我的帖子,并在我的设置中添加了数据库条目。py您可以尝试使用字符串cast NAME path str(os.path.join(BASE_DIR,“db.sqlite3”))查看,并对该问题进行可能的解释。在较新的Django版本中,该问题似乎已得到修复。请参阅,并提供有关该问题的可能解释。这个问题似乎在较新的Django版本中得到了解决。