I have an application with a MySQL database, and I am working with django. The website works fine with my settings.py configured as this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': '<user>$<database>',
'USER': '<user>',
'PASSWORD': '<password>',
'HOST': 'capitale.mysql.pythonanywhere-services.com',
}
}
I'v replaced above the tags USER, PASSWORD and NAME. But I think they are also correct, since my website is working fine and I have a view listing things from one of the tables.
However, I DO have an Always -on task configured. It processes somethings and create registries in one of the tables of my database. It was working just fine, but then stopped working.
The command I used in my task is:
source /home/capitale/.virtualenvs/myenv/bin/activate && python /home/capitale/capitale/manage.py obtem_cnpjs_rf
First, it activates the myenv environment where I've deployed my django apllication and after it starts a custom Django command created by me and called obtem_cnpjs_rf.
This command was created in the folder capitale/clientes/management/commands/. It contains a loop that checks some condition and then do something if the condition is true at the database. However, it is not working anymore and the log says this:
Jul 7 19:42:42 Traceback (most recent call last):
Jul 7 19:42:42 File "/home/capitale/.virtualenvs/myenv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection
Jul 7 19:42:42 self.connect()
Jul 7 19:42:42 File "/home/capitale/.virtualenvs/myenv/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
Jul 7 19:42:42 return func(*args, **kwargs)
Jul 7 19:42:42 File "/home/capitale/.virtualenvs/myenv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 197, in connect
Jul 7 19:42:42 self.connection = self.get_new_connection(conn_params)
Jul 7 19:42:42 File "/home/capitale/.virtualenvs/myenv/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
Jul 7 19:42:42 return func(*args, **kwargs)
Jul 7 19:42:42 File "/home/capitale/.virtualenvs/myenv/lib/python3.8/site-packages/django/db/backends/mysql/base.py", line 233, in get_new_connection
Jul 7 19:42:42 return Database.connect(**conn_params)
Jul 7 19:42:42 File "/home/capitale/.virtualenvs/myenv/lib/python3.8/site-packages/MySQLdb/__init__.py", line 84, in Connect
Jul 7 19:42:42 return Connection(*args, **kwargs)
Jul 7 19:42:42 File "/home/capitale/.virtualenvs/myenv/lib/python3.8/site-packages/MySQLdb/connections.py", line 179, in __init__
Jul 7 19:42:42 super(Connection, self).__init__(*args, **kwargs2)
Jul 7 19:42:42 MySQLdb._exceptions.OperationalError: (2005, "Unknown MySQL server host 'capitale.mysql.pythonanywhere-services.com' (110)")
My obtem_cnpjs_rf.py file contains the following first lines, where I import django.settings, for instance.
from django.core.management.base import BaseCommand
from clientes.models import Empresa, SocioEmpresa, ConjImportacoesEmpresas, ImportacaoEmpresa
from django.db.models import Q
from django.conf import settings
Any idea on what is happening and how can I solve this?