I have tried everything I can think of to run my initial migrations using python manage.py migrate
and get my django app up. I am currently getting this error:
Traceback (most recent call last):
File "manage.py", line 24, in <module>
execute_from_command_line(sys.argv)
File "/usr/lib/python3/dist-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/usr/lib/python3/dist-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/python3/dist-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/lib/python3/dist-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/usr/lib/python3/dist-packages/django/core/management/commands/dbshell.py", line 22, in handle
connection.client.runshell()
File "/usr/lib/python3/dist-packages/django/db/backends/dummy/base.py", line 20, in complain
raise ImproperlyConfigured("settings.DATABASES is improperly configured. "
django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
But this is the DATABASES var in my settings.py
file:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
- The db.sqlite3 file is at the location specified in the 'NAME' key.
- The app folder is in a subdirectory and uniquely named.
- The BASE_DIR var is constructed correctly and not causing the location string in the NAME key to be malformed.
- The
models.py
file is in the /app folder subdirectory.
I am completely out of ideas on how to get this to work and considering giving up on making this project altogether.
In case it helps here is my project tree
.
└── randoplant
├── db.sqlite3
├── __init__.py
├── manage.py
├── __pycache__
│ └── __init__.cpython-38.pyc
└── randoplant_app
├── admin.py
├── __init__.py
├── models.py
├── plant.py
├── __pycache__
│ ├── admin.cpython-38.pyc
│ ├── __init__.cpython-38.pyc
│ ├── models.cpython-38.pyc
│ ├── settings.cpython-38.pyc
│ └── urls.cpython-38.pyc
├── settings.py
├── urls.py
└── wsgi.py
Please help. I am running Django version 2.2.12 and I am in a WSL shell.
CodePudding user response:
the problem is the name, you should do the following:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'db.sqlite3',
}
}
instead of giving a path to the database in the name field and it will automatically create a DB file for you, You can read the DATABASES settings in the official documentation for more information.
CodePudding user response:
I have checked your project folder and is organized as recommended try using the setting below or code below in your settings file:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
Make sure that he BASE_DIR is defined in your settings file and imported the path library as below:-
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
But if you insist on using your previous database configuration file please make sure that the os and path module are imported.