3

I created a virtual environment for my new project, installed django and started the new project. However, whenever i run a line of code with manage.py i get this long error.

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

Database Entry:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}
8

4 Answers 4

5

It does seem NAME is being converted to pathlib.Path (WindowsPath) object instead of string which then cannot be used in Django in same way as os.path expects strings (Not 100% sure as did not investigate in depth)

So casting in string would be appropriate

'NAME': str(os.path.join(BASE_DIR, "db.sqlite3"))
Sign up to request clarification or add additional context in comments.

1 Comment

See my answer to a similar question with a possible explanation of the issue. The issue seems to be fixed in newer Django versions.
2

Make sure you really execute your command in the venv (you should see (venv))

If you are then as @iklinac said, this should fixe your issue:

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

Comments

0

Also, for Django>=3.1, the path module is included in place of the os module. Therefore, use:

'NAME': str(BASE_DIR / 'db.sqlite3')

So, DB sqlite3 settings will look like this in settings.py.

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.sqlite3',
    'NAME': str(BASE_DIR / 'db.sqlite3')
    }
}

Comments

0

It's not obvious, but when creating a new project, if the 'static' folder is created and you have such a variable STATICFILES_DIRS = (BASE_DIR / 'static',). Don't forget to put a comma at the end. If you do not put a comma, this will cause this error. Perhaps there will be some similar variable.

2 Comments

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
This is due to the fact that a tuple must be passed. And a tuple with one element looks exactly like this (BASE_DIR / "static",)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.