How to resolve error in makemigrations (Django)

Asked

Viewed 30 times

-1

I’m trying to execute command python manage.py makemigrations, and is generating this return on my terminal, even when I try to start the Django server using the python manage.py runserver, the terminal returns me the same error.

(venv) PS C:\Users\rhama\Documents\GitHub\Django> python manage.py makemigrations
Traceback (most recent call last):
  File "C:\Users\rhama\Documents\GitHub\Django\venv\lib\site-packages\django\db\utils.py", line 111, in load_backend
    return import_module('%s.base' % backend_name)
  File "c:\users\rhama\appdata\local\programs\python\python39\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'django.db.backends.postgressql'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\rhama\Documents\GitHub\Django\manage.py", line 22, in <module>
    main()
  File "C:\Users\rhama\Documents\GitHub\Django\manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\rhama\Documents\GitHub\Django\venv\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line        
    utility.execute()
  File "C:\Users\rhama\Documents\GitHub\Django\venv\lib\site-packages\django\core\management\__init__.py", line 395, in execute
    django.setup()
  File "C:\Users\rhama\Documents\GitHub\Django\venv\lib\site-packages\django\__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Users\rhama\Documents\GitHub\Django\venv\lib\site-packages\django\apps\registry.py", line 114, in populate
    app_config.import_models()
  File "C:\Users\rhama\Documents\GitHub\Django\venv\lib\site-packages\django\apps\config.py", line 301, in import_models
    self.models_module = import_module(models_module_name)
  File "c:\users\rhama\appdata\local\programs\python\python39\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 855, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "C:\Users\rhama\Documents\GitHub\Django\receitas\models.py", line 5, in <module>
    class Receita(models.Model):
  File "C:\Users\rhama\Documents\GitHub\Django\venv\lib\site-packages\django\db\models\base.py", line 122, in __new__
    new_class.add_to_class('_meta', Options(meta, app_label))
  File "C:\Users\rhama\Documents\GitHub\Django\venv\lib\site-packages\django\db\models\base.py", line 326, in add_to_class
    value.contribute_to_class(cls, name)
  File "C:\Users\rhama\Documents\GitHub\Django\venv\lib\site-packages\django\db\models\options.py", line 207, in contribute_to_class
    self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
  File "C:\Users\rhama\Documents\GitHub\Django\venv\lib\site-packages\django\utils\connection.py", line 15, in __getattr__
    return getattr(self._connections[self._alias], item)
  File "C:\Users\rhama\Documents\GitHub\Django\venv\lib\site-packages\django\utils\connection.py", line 62, in __getitem__
    conn = self.create_connection(alias)
  File "C:\Users\rhama\Documents\GitHub\Django\venv\lib\site-packages\django\db\utils.py", line 204, in create_connection
    backend = load_backend(db['ENGINE'])
  File "C:\Users\rhama\Documents\GitHub\Django\venv\lib\site-packages\django\db\utils.py", line 122, in load_backend
    raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: 'django.db.backends.postgressql' isn't an available database backend or couldn't be imported. Check the above exception. To use one of the built-in backends, use 'django.db.backends.XXX', where XXX is one of:
    'mysql', 'oracle', 'postgresql', 'sqlite3'

All this error started after I inserted a class in my file py.models

from django.db import models
from datetime import datetime


class Receita(models.Model):
    nome_receita = models.CharField(max_length=200)
    ingredientes = models.TextField()
    modo_preparo = models.TextField()
    tempo_preparo = models.IntegerField()
    rendimento = models.CharField(max_length=100)
    categoria = models.CharField(max_length=100)
    date_receita = models.DateField(default = datetime.now, blank=True)

1 answer

1

I think you are not used to the log (or stacktrace). In the last line of the error, the main error and possible solutions are shown.

Basically you defined the ENGINE in a wrong way, sometimes it happens. Instead of Django.db.backends.postgressql should be Django.db.backends.postgresql. For lack of attention or heavy finger, added an "s" more.

I usually use the Django.db.backends.postgresql_psycopg2.

To see the configs in the documentation: documantacao#engine and pg_notes.

I hope I’ve helped!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.