How to Solve Error Message django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details. in Django

Posted on

The error is already exist as the title of the article. The focus of this article is to show how to solve the error as is. The error message appear upon executing a command to migrate database of an application. In this context, it is a Django-based web application. The following is the actual command execution where the error message suddenly appear :

(myenv) C:\python-win\app>python manage.py migrate
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\python-win\myenv\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\python-win\myenv\lib\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\python-win\myenv\lib\site-packages\django\core\management\base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\python-win\myenv\lib\site-packages\django\core\management\base.py", line 369, in execute
output = self.handle(*args, **options)
File "C:\python-win\myenv\lib\site-packages\django\core\management\base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "C:\python-win\myenv\lib\site-packages\django\core\management\commands\migrate.py", line 86, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "C:\python-win\myenv\lib\site-packages\django\db\migrations\executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "C:\python-win\myenv\lib\site-packages\django\db\migrations\loader.py", line 49, in __init__
self.build_graph()
File "C:\python-win\myenv\lib\site-packages\django\db\migrations\loader.py", line 212, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "C:\python-win\myenv\lib\site-packages\django\db\migrations\recorder.py", line 76, in applied_migrations
if self.has_table():
File "C:\python-win\myenv\lib\site-packages\django\db\migrations\recorder.py", line 56, in has_table
return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
File "C:\python-win\myenv\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\python-win\myenv\lib\site-packages\django\db\backends\base\base.py", line 260, in cursor
return self._cursor()
File "C:\python-win\myenv\lib\site-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.

The command execution above is :

python manage.py migrate

The command is to migrate all the necessary thing to the database as in the definition in the ‘settings.py’ file in the project folder. As in the last line of the command execution above, the error message has already exist. The error message is : django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details. So, look for the ‘DATABASES’ attribute or parameter in the file. Normally, in this context, the configuration is intended to be suitable for connecting to MySQL Database as the following entry in ‘settings.py’ file :

DATABASES = {
     'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'db_name',
        'USER': 'db_user',
        'PASSWORD': 'db_password',
        'HOST': 'db_host',
        'PORT': 'db_port',
    }
}

The above setting have different values depend on the environment of the machine which is the ‘db_name’, ‘db_user’, ‘db_password’, ‘db_host’ and ‘db_port’. Accidentally, the setting has already in its correct form. But after checking the entire content of the file further, below the above DATABASES configuration lines, there are another DATABASES definition again as follows :

DATABASES = {
}

Accidentally, it override the previous correct database configuration. So, in order to solve the problem, just erase the above line which is a duplicate definition of ‘DATABASES’. But it is a false definition of ‘DATABASES’ attribute. After erasing it, it actually solve the problem.

Leave a Reply