Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

Quando vai criar o Banco

(venv) C:\Users\emanuel.almeida\Documents\alura-estudos>python manage.py migration
Traceback (most recent call last):
  File "C:\Users\emanuel.almeida\Documents\alura-estudos\venv\lib\site-packages\django\db\backends\postgresql\base.py", line 25, in <module>
    import psycopg2 as Database
ModuleNotFoundError: No module named 'psycopg2'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\emanuel.almeida\Documents\alura-estudos\manage.py", line 22, in <module>
    main()
  File "C:\Users\emanuel.almeida\Documents\alura-estudos\manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\emanuel.almeida\Documents\alura-estudos\venv\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "C:\Users\emanuel.almeida\Documents\alura-estudos\venv\lib\site-packages\django\core\management\__init__.py", line 377, in execute
    django.setup()
  File "C:\Users\emanuel.almeida\Documents\alura-estudos\venv\lib\site-packages\django\__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Users\emanuel.almeida\Documents\alura-estudos\venv\lib\site-packages\django\apps\registry.py", line 114, in populate
    app_config.import_models()
  File "C:\Users\emanuel.almeida\Documents\alura-estudos\venv\lib\site-packages\django\apps\config.py", line 211, in import_models
    self.models_module = import_module(models_module_name)
  File "C:\Users\emanuel.almeida\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 790, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "C:\Users\emanuel.almeida\Documents\alura-estudos\receitas\models.py", line 5, in <module>
    class Receita(models.Model):
  File "C:\Users\emanuel.almeida\Documents\alura-estudos\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\emanuel.almeida\Documents\alura-estudos\venv\lib\site-packages\django\db\models\base.py", line 326, in add_to_class
    value.contribute_to_class(cls, name)
  File "C:\Users\emanuel.almeida\Documents\alura-estudos\venv\lib\site-packages\django\db\models\options.py", line 206, in contribute_to_class
    self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
  File "C:\Users\emanuel.almeida\Documents\alura-estudos\venv\lib\site-packages\django\db\__init__.py", line 28, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "C:\Users\emanuel.almeida\Documents\alura-estudos\venv\lib\site-packages\django\db\utils.py", line 214, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "C:\Users\emanuel.almeida\Documents\alura-estudos\venv\lib\site-packages\django\db\utils.py", line 111, in load_backend
    return import_module('%s.base' % backend_name)
  File "C:\Users\emanuel.almeida\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 790, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "C:\Users\emanuel.almeida\Documents\alura-estudos\venv\lib\site-packages\django\db\backends\postgresql\base.py", line 29, in <module>
    raise ImproperlyConfigured("Error loading psycopg2 module")
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module

(venv) C:\Users\emanuel.almeida\Documents\alura-estudos>

Quando tento colocar para ser copiado para o banco de dados os comandos que sao passados pelo instrutor da aula nao funciona.

2 respostas
solução!

Achei a solução haha, depois de ficar fuçando por horas, o comando makemigrations tinha que ser dado (nao sei porque) e aberto o console na pagina de models.py. Depois que abrir a tela e o console nela o comando funcionou.

Fala Emanuel, como vai?

Que bom que conseguiu. Existem 2 comandos para para interagir com banco: o migrate e o makemigrations.

Assim que finalizamos as alterações no modelo, executamos o makemigrations que é responsável por criar novas migrações com base nas alterações feitas em seus modelos e depois o migrate, que é responsável por aplicar migrações no banco de dados de fato.

Bons estudos e conte com a Alura!