Abrufen eines typeError-Fehlers im Django-Projekt
Aug 17 2020
Ich habe eine virtuelle Umgebung für mein neues Projekt erstellt, Django installiert und das neue Projekt gestartet. Wenn ich jedoch eine Codezeile mit manage.py ausführe, wird dieser lange Fehler angezeigt.
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
Datenbankeintrag:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
Antworten
5 iklinac Aug 17 2020 at 11:33
Es scheint, dass NAME in ein pathlib.Path ( WindowsPath ) -Objekt anstelle eines Strings konvertiert wird, das dann in Django nicht auf die gleiche Weise verwendet werden kann, wie os.path Strings erwartet (nicht 100% sicher, da nicht eingehend untersucht wurde).
Ein Casting in einer Schnur wäre also angebracht
'NAME': str(os.path.join(BASE_DIR, "db.sqlite3"))
2 FirePanda Oct 05 2020 at 17:48
Stellen Sie sicher, dass Sie Ihren Befehl wirklich im venv ausführen (Sie sollten sehen (venv))
Wenn Sie dann wie @iklinac gesagt haben, sollte dies Ihr Problem beheben:
'NAME': str(os.path.join(BASE_DIR, "db.sqlite3"))