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

Erro ao migrar banco

Erro ao executar comando "python manage.py makemigrations"

Procurando uma solução, mas...

(venv-django-todolist) vagrant@ubuntu-bionic:/vagrant/jenkins-todo-list$ python3 manage.py makemigrations Traceback (most recent call last): File "manage.py", line 8, in from django.core.management import execute_from_command_line File "/vagrant/jenkins-todo-list/venv-django-todolist/lib/python3.6/site-packages/django/core/management/init.py", line 11, in from django.apps import apps ImportError: cannot import name 'apps'

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

Traceback (most recent call last): File "manage.py", line 14, in ) from exc ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment? (venv-django-todolist) vagrant@ubuntu-bionic:/vagrant/jenkins-todo-list$

Versão Python: (venv-django-todolist) vagrant@ubuntu-bionic:/vagrant/jenkins-todo-list$ python --version Python 3.6.9

3 respostas

Olá Paulo, tudo bem? Você instalou todas as dependências do Python? Deu algum erro no momento da instalação? Você poderia descrever mais detalhadamente os passos que você realizou até o momento do erro? É um erro bastante incomum e preciso de mais detalhes para poder entender o que está acontecendo e poder ti indicar alguma solução!

Fico aguardando retorno!

Jonilson, bom dia.

Esse erro foi apresentado no momento que rodei : " pip install -r requirements.txt "

(venv-django-todolist) vagrant@ubuntu-bionic:/vagrant/jenkins-todo-list$ pip install -r requirements.txt Requirement already satisfied: wheel==0.35.1 in ./venv-django-todolist/lib/python3.6/site-packages (from -r requirements.txt (line 1)) (0.35.1) Collecting Django==3.1.1 Downloading Django-3.1.1-py3-none-any.whl (7.8 MB) |████████████████████████████████| 7.8 MB 3.9 MB/s Requirement already satisfied: django-bootstrap-form==3.4 in ./venv-django-todolist/lib/python3.6/site-packages (from -r requirements.txt (line 3)) (3.4) Requirement already satisfied: django-glrm==1.1.3 in ./venv-django-todolist/lib/python3.6/site-packages (from -r requirements.txt (line 4)) (1.1.3) Requirement already satisfied: django-widget-tweaks==1.4.3 in ./venv-django-todolist/lib/python3.6/site-packages (from -r requirements.txt (line 5)) (1.4.3) Requirement already satisfied: mysqlclient==1.4.2.post1 in ./venv-django-todolist/lib/python3.6/site-packages (from -r requirements.txt (line 6)) (1.4.2.post1) Requirement already satisfied: pytz==2018.9 in ./venv-django-todolist/lib/python3.6/site-packages (from -r requirements.txt (line 7)) (2018.9) Requirement already satisfied: uWSGI==2.0.18 in ./venv-django-todolist/lib/python3.6/site-packages (from -r requirements.txt (line 8)) (2.0.18) Requirement already satisfied: gunicorn==19.9.0 in ./venv-django-todolist/lib/python3.6/site-packages (from -r requirements.txt (line 9)) (19.9.0) Requirement already satisfied: python-decouple==3.1 in ./venv-django-todolist/lib/python3.6/site-packages (from -r requirements.txt (line 10)) (3.1) Collecting asgiref~=3.2.10 Downloading asgiref-3.2.10-py3-none-any.whl (19 kB) Collecting sqlparse>=0.2.2 Downloading sqlparse-0.3.1-py2.py3-none-any.whl (40 kB) |████████████████████████████████| 40 kB 11.5 MB/s Installing collected packages: asgiref, sqlparse, Django Attempting uninstall: Django Found existing installation: Django 2.1.7 Uninstalling Django-2.1.7: Successfully uninstalled Django-2.1.7

ERROR: Could not install packages due to an EnvironmentError: [Errno 39] Directory not empty: 'apps'

(venv-django-todolist) vagrant@ubuntu-bionic:/vagrant/jenkins-todo-list$


Porém eu rodei novamente : " pip install -r requirements.txt " , como você disse no vídeo que as vezes acontece algo parecido, mas bastava rodar novamente, aí a saída foi essa:

(venv-django-todolist) vagrant@ubuntu-bionic:/vagrant/jenkins-todo-list$ (venv-django-todolist) vagrant@ubuntu-bionic:/vagrant/jenkins-todo-list$ pip install -r requirements.txt Requirement already satisfied: wheel==0.35.1 in ./venv-django-todolist/lib/python3.6/site-packages (from -r requirements.txt (line 1)) (0.35.1) Requirement already satisfied: Django==3.1.1 in ./venv-django-todolist/lib/python3.6/site-packages (from -r requirements.txt (line 2)) (3.1.1) Requirement already satisfied: django-bootstrap-form==3.4 in ./venv-django-todolist/lib/python3.6/site-packages (from -r requirements.txt (line 3)) (3.4) Requirement already satisfied: django-glrm==1.1.3 in ./venv-django-todolist/lib/python3.6/site-packages (from -r requirements.txt (line 4)) (1.1.3) Requirement already satisfied: django-widget-tweaks==1.4.3 in ./venv-django-todolist/lib/python3.6/site-packages (from -r requirements.txt (line 5)) (1.4.3) Requirement already satisfied: mysqlclient==1.4.2.post1 in ./venv-django-todolist/lib/python3.6/site-packages (from -r requirements.txt (line 6)) (1.4.2.post1) Requirement already satisfied: pytz==2018.9 in ./venv-django-todolist/lib/python3.6/site-packages (from -r requirements.txt (line 7)) (2018.9) Requirement already satisfied: uWSGI==2.0.18 in ./venv-django-todolist/lib/python3.6/site-packages (from -r requirements.txt (line 8)) (2.0.18) Requirement already satisfied: gunicorn==19.9.0 in ./venv-django-todolist/lib/python3.6/site-packages (from -r requirements.txt (line 9)) (19.9.0) Requirement already satisfied: python-decouple==3.1 in ./venv-django-todolist/lib/python3.6/site-packages (from -r requirements.txt (line 10)) (3.1) Requirement already satisfied: asgiref~=3.2.10 in ./venv-django-todolist/lib/python3.6/site-packages (from Django==3.1.1->-r requirements.txt (line 2)) (3.2.10) Requirement already satisfied: sqlparse>=0.2.2 in ./venv-django-todolist/lib/python3.6/site-packages (from Django==3.1.1->-r requirements.txt (line 2)) (0.3.1)

Ou seja, aparentemente tudo ok. Mas não roda a migração.

solução!

Paulo, parece que o projeto não está reconhecendo que o Django foi instalado, e isso pode tem relação com o ambiente virtual. Então você poderia tentar seguir os passos a abaixo e falar o resultado pra gente:

  • Excluir a pasta do ambiente virtual e criar um novo ambiente virtual usando o comando:
    python -m venv venv
  • Fazer a ativação do ambiente, só pode fazer isso usando o comando:
    source venv/bin/activate
  • Com o ambiente ativo, você pode tentar instalar as dependências novamente com o comando:
    pip install -r requirements.txt
  • E depois, tente executar as migrations com o comando:
    python manage.py makemigrations

Se o procedimento acima ainda resultar em um erro você poderia tentar executar as migrations indicando explicitamente a aplicação da seguinte forma:

python manage.py makemigrations nome_do_app_aqui

E fala pra gente o resultado!