return database_name == ':memory:' or 'mode=memory' in database_name TypeError: argument of type 'WindowsPath' is not iterable
I just answered that same error in this question How can I resolve the argument of type 'WindowsPath' is not iterable in django? not opening any pdf or csv files
It seems like the setting DATABASES - NAME expects a string, not a Path
object.
In your settings try changing this line
'NAME': BASE_DIR / 'db.sqlite3',
to
'NAME': str(BASE_DIR / 'db.sqlite3'),
so that NAME
is a string instead of a Path
.
The error comes from this line of code django/db/backends/sqlite3/creation.py#L13
and it seems that this commit solves the issue, so in Django v3.1.1
there is no need to use 'NAME': str(BASE_DIR / 'db.sqlite3'),
anymore, just using 'NAME': BASE_DIR / 'db.sqlite3',
should sufice.
I fixed this error changed line for database name into file settings.py to'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
For older versions or third-party package settings, you will probably need to use str()
around the result.
For example, if you are using the SQLite database backend, before opening the database file it checks if the path contains "mode=memory"
. For this to work, you’ll need to use str()
when passing the path in NAME
:
DATABASES = { "default": { "ENGINE": "django.db.backends.sqlite3", "NAME": str(BASE_DIR / "db.sqlite3"), }}
For any other errors you might encounter, using str()
should fix them.
Source: https://adamj.eu/tech/2020/03/16/use-pathlib-in-your-django-project/