Connecting django to MS SQL Server using odbc - sql-server

I'm getting an error when trying to execute manage.py runserver. I've installed django-pyodbc and the odbc driver 17 for sql server. Do I need to import pyodbc somewhere in the project? I am very new to django and python in general but I want to use ms sql server instead of sqlite. This is the code in manage.py:
DATABASES = {
'default': {
'ENGINE': 'sql_server.pyodbc',
'NAME': 'database',
'HOST': 'localhost',
'USER': 'user',
'PASSWORD': 'password',
'OPTIONS': {'ODBC Driver 17 for SQL Server',
}
}
}
Here is the error:
(venv) C:\Users\Kirk\PycharmProjects\PyShop>manage.py runserver
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x000001770CD61438>
Traceback (most recent call last):
File "C:\Users\Kirk\PycharmProjects\PyShop\venv\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "C:\Users\Kirk\PycharmProjects\PyShop\venv\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "C:\Users\Kirk\PycharmProjects\PyShop\venv\lib\site-packages\django\utils\autoreload.py", line 248, in raise_last_exception
raise _exception[1]
File "C:\Users\Kirk\PycharmProjects\PyShop\venv\lib\site-packages\django\core\management\__init__.py", line 337, in execute
autoreload.check_errors(django.setup)()
File "C:\Users\Kirk\PycharmProjects\PyShop\venv\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "C:\Users\Kirk\PycharmProjects\PyShop\venv\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Kirk\PycharmProjects\PyShop\venv\lib\site-packages\django\apps\registry.py", line 112, in populate
app_config.import_models()
File "C:\Users\Kirk\PycharmProjects\PyShop\venv\lib\site-packages\django\apps\config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\Kirk\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\Kirk\PycharmProjects\PyShop\venv\lib\site-packages\django\contrib\auth\models.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "C:\Users\Kirk\PycharmProjects\PyShop\venv\lib\site-packages\django\contrib\auth\base_user.py", line 47, in <module>
class AbstractBaseUser(models.Model):
File "C:\Users\Kirk\PycharmProjects\PyShop\venv\lib\site-packages\django\db\models\base.py", line 101, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "C:\Users\Kirk\PycharmProjects\PyShop\venv\lib\site-packages\django\db\models\base.py", line 305, in add_to_class
value.contribute_to_class(cls, name)
File "C:\Users\Kirk\PycharmProjects\PyShop\venv\lib\site-packages\django\db\models\options.py", line 203, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "C:\Users\Kirk\PycharmProjects\PyShop\venv\lib\site-packages\django\db\__init__.py", line 33, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:\Users\Kirk\PycharmProjects\PyShop\venv\lib\site-packages\django\db\utils.py", line 203, in __getitem__
conn = backend.DatabaseWrapper(db, alias)
File "C:\Users\Kirk\PycharmProjects\PyShop\venv\lib\site-packages\sql_server\pyodbc\base.py", line 193, in __init__
self.driver_charset = opts.get('driver_charset', None)
AttributeError: 'set' object has no attribute 'get
'
Any help is appreciated. Thank you.

Change your options to following. Error might be caused by string parsing function of pyodbc library.
'OPTIONS': {
'driver': 'ODBC Driver 17 for SQL Server',
}
or
‘OPTIONS’: {“ODBC Driver 17 for SQL Server”, }

Related

ImportError: cannot import name 'urlresolvers' from 'django.core'

Can anybody help figuring out the issue and solution.Here is the error for python 3.10.6 and django 3.2.17
python manage.py runserver 0.0.0.0:8001
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
self.run()
File "/usr/lib/python3.10/threading.py", line 953, in run
self._target(*self._args, **self._kwargs)
File "/home/mindmatrix/Documents/demo/lib/python3.10/site- packages/django/utils/autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "/home/mindmatrix/Documents/demo/lib/python3.10/site-packages/django/core/management/commands/runserver.py", line 110, in inner_run
autoreload.raise_last_exception()
File "/home/mindmatrix/Documents/demo/lib/python3.10/site-packages/django/utils/autoreload.py", line 87, in raise_last_exception
raise _exception[1]
File "/home/mindmatrix/Documents/demo/lib/python3.10/site-packages/django/core/management/__init__.py", line 375, in execute
autoreload.check_errors(django.setup)()
File "/home/mindmatrix/Documents/demo/lib/python3.10/site-packages/django/utils/autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "/home/mindmatrix/Documents/demo/lib/python3.10/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/mindmatrix/Documents/demo/lib/python3.10/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/home/mindmatrix/Documents/demo/lib/python3.10/site-packages/django/apps/config.py", line 301, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/home/mindmatrix/Documents/job_portal_updated_Feb_10/peeldb/models.py", line 8, in <module>
from oauth2client.contrib.django_util.models import CredentialsField
File "/home/mindmatrix/Documents/demo/lib/python3.10/site-packages/oauth2client/contrib/django_util/__init__.py", line 233, in <module>
from django.core import urlresolvers
ImportError: cannot import name 'urlresolvers' from 'django.core' (/home/mindmatrix/Documents/demo/lib/python3.10/site-packages/django/core/__init__.py)
I am trying for version upgrade of the open source project. I have upgraded all the neccessary requirements for the project. Now while running the command python manage.py runserver I am facing this issue.If any one can help?? I`

Having trouble with pyodbc on django

I am working on django project. And testing Sql Server database.
I am using korean linux hosting service gabia. So I don't have any root access.
Even this hosting company blocked yum and rpm.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: libodbc.so.2: cannot open shared object file: No such file or directory
I am keep having this kind of trouble when I import pyodbc. But I can fully use pymssql module.
I have no idea what is wrong with this linux...
This is when I connect django to mssql database with mssql-django package.
Traceback (most recent call last):
File "/web/.local/lib/python3.9/site-packages/mssql/base.py", line 16, in <module>
import pyodbc as Database
ImportError: libodbc.so.2: cannot open shared object file: No such file or directory
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/wsgiref/handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "/web/.local/lib/python3.9/site-packages/django/core/handlers/wsgi.py", line 130, in __call__
signals.request_started.send(sender=self.__class__, environ=environ)
File "/web/.local/lib/python3.9/site-packages/django/dispatch/dispatcher.py", line 176, in send
return [
File "/web/.local/lib/python3.9/site-packages/django/dispatch/dispatcher.py", line 177, in <listcomp>
(receiver, receiver(signal=self, sender=sender, **named))
File "/web/.local/lib/python3.9/site-packages/django/db/__init__.py", line 46, in reset_queries
for conn in connections.all():
File "/web/.local/lib/python3.9/site-packages/django/utils/connection.py", line 76, in all
return [self[alias] for alias in self]
File "/web/.local/lib/python3.9/site-packages/django/utils/connection.py", line 76, in <listcomp>
return [self[alias] for alias in self]
File "/web/.local/lib/python3.9/site-packages/django/utils/connection.py", line 62, in __getitem__
conn = self.create_connection(alias)
File "/web/.local/lib/python3.9/site-packages/django/db/utils.py", line 208, in create_connection
backend = load_backend(db["ENGINE"])
File "/web/.local/lib/python3.9/site-packages/django/db/utils.py", line 113, in load_backend
return import_module("%s.base" % backend_name)
File "/usr/local/lib/python3.9/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 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/web/.local/lib/python3.9/site-packages/mssql/base.py", line 18, in <module>
raise ImproperlyConfigured("Error loading pyodbc module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading pyodbc module: libodbc.so.2: cannot open shared object file: No such file or directory
This linux is CentOS 7
I've tried to install unixODBC on /web/.local directory which I can access into. And I successfully executed unixodbc alone, but not with python pyodbc.
I failed to install FreeTDS because I cannot find any way to install FreeTDS on this linux with tar file.
I wonder if I can change the installation path written on pyodbc package file. If I can, then I can fix this problem with changing the installation root of unixODBC to my accessable directory.

Cannot connect to mssql database using Django (Mac OS)

My mssql database is inside the docker container. When trying to connect to the database using azure data studio I don't get any errors, whereas when I'm trying to connect to the db using Django I get the following error:
Traceback (most recent call last):
File "/usr/local/Cellar/python#3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 954, in _bootstrap_inner
self.run()
File "/usr/local/Cellar/python#3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 892, in run
self._target(*self._args, **self._kwargs)
File "/Users/aleksandr/Desktop/teplo/teplo_back/venv/lib/python3.9/site-packages/django/utils/autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "/Users/aleksandr/Desktop/teplo/teplo_back/venv/lib/python3.9/site-packages/django/core/management/commands/runserver.py", line 121, in inner_run
self.check_migrations()
File "/Users/aleksandr/Desktop/teplo/teplo_back/venv/lib/python3.9/site-packages/django/core/management/base.py", line 486, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "/Users/aleksandr/Desktop/teplo/teplo_back/venv/lib/python3.9/site-packages/django/db/migrations/executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "/Users/aleksandr/Desktop/teplo/teplo_back/venv/lib/python3.9/site-packages/django/db/migrations/loader.py", line 53, in __init__
self.build_graph()
File "/Users/aleksandr/Desktop/teplo/teplo_back/venv/lib/python3.9/site-packages/django/db/migrations/loader.py", line 220, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/Users/aleksandr/Desktop/teplo/teplo_back/venv/lib/python3.9/site-packages/django/db/migrations/recorder.py", line 77, in applied_migrations
if self.has_table():
File "/Users/aleksandr/Desktop/teplo/teplo_back/venv/lib/python3.9/site-packages/django/db/migrations/recorder.py", line 55, in has_table
with self.connection.cursor() as cursor:
File "/Users/aleksandr/Desktop/teplo/teplo_back/venv/lib/python3.9/site-packages/django/utils/asyncio.py", line 33, in inner
return func(*args, **kwargs)
File "/Users/aleksandr/Desktop/teplo/teplo_back/venv/lib/python3.9/site-packages/django/db/backends/base/base.py", line 259, in cursor
return self._cursor()
File "/Users/aleksandr/Desktop/teplo/teplo_back/venv/lib/python3.9/site-packages/mssql/base.py", line 230, in _cursor
conn = super()._cursor()
File "/Users/aleksandr/Desktop/teplo/teplo_back/venv/lib/python3.9/site-packages/django/db/backends/base/base.py", line 235, in _cursor
self.ensure_connection()
File "/Users/aleksandr/Desktop/teplo/teplo_back/venv/lib/python3.9/site-packages/django/utils/asyncio.py", line 33, in inner
return func(*args, **kwargs)
File "/Users/aleksandr/Desktop/teplo/teplo_back/venv/lib/python3.9/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/Users/aleksandr/Desktop/teplo/teplo_back/venv/lib/python3.9/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/Users/aleksandr/Desktop/teplo/teplo_back/venv/lib/python3.9/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/Users/aleksandr/Desktop/teplo/teplo_back/venv/lib/python3.9/site-packages/django/utils/asyncio.py", line 33, in inner
return func(*args, **kwargs)
File "/Users/aleksandr/Desktop/teplo/teplo_back/venv/lib/python3.9/site-packages/django/db/backends/base/base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "/Users/aleksandr/Desktop/teplo/teplo_back/venv/lib/python3.9/site-packages/mssql/base.py", line 326, in get_new_connection
conn = Database.connect(connstr,
django.db.utils.OperationalError: ('08001', '[08001] [Microsoft][ODBC Driver 17 for SQL Server]Client unable to establish connection (0) (SQLDriverConnect)')
Django db configuration:
DATABASES = {
'default': {
'ENGINE': 'mssql',
'NAME': 'db_name',
'HOST': 'localhost',
'PORT': 1433,
'USER': 'sa',
'PASSWORD': 'db_pwd',
'OPTIONS': {
'driver': 'ODBC Driver 17 for SQL Server',
}
}
}
Installed packages:
Django==3.2.9
mssql-django==1.0
pyodbc==4.0.30
I eventually managed to solve the problem. The trouble was linked to SSL.
First, you have to open the folder /usr/local/opt. There, you can find the openssl#1.1 folder. You have to grab all of the files from there and put them into the openssl folder.
After that, I managed to run Django server successfully.

Can't seem to make the makemigration work

model.py:
from django.db import models
# Create your models here.
class Departments(models.Model):
DepartmentId = models.AutoField(primary_key=True)
DepartmentName = models.CharField(max_length=500)
class Employees(models.Model):
EmployeesId = models.AutoField(primary_key=True)
EmployeesName = models.CharField(max_length=500)
Department = models.CharField(max_length=500)
DateOfJoining = models.DateField()
PhotoFileName = models.CharField(max_length=500)
cmd:
Microsoft Windows [Version 10.0.19042.1052]
(c) Microsoft Corporation. All rights reserved.
C:\tutorial\api\DjangoAPI>python manage.py makemigrations EmployeeApp
Traceback (most recent call last):
File "C:\tutorial\api\DjangoAPI\manage.py", line 22, in <module>
main()
File "C:\tutorial\api\DjangoAPI\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\Collins\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
utility.execute()
File "C:\Users\Collins\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\__init__.py", line 395, in execute
django.setup()
File "C:\Users\Collins\AppData\Local\Programs\Python\Python39\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Collins\AppData\Local\Programs\Python\Python39\lib\site-packages\django\apps\registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "C:\Users\Collins\AppData\Local\Programs\Python\Python39\lib\site-packages\django\apps\config.py", line 212, in create
mod = import_module(mod_path)
File "C:\Users\Collins\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 'Employee'
C:\tutorial\api\DjangoAPI>
Im not sure why its not working because i found similar tutorials online and every other line was similar to mine. I always get the error; "No module named 'Employee' when i try running the server.
Thank you inadvance.

Installation step fails: docker exec -it kiwi_web /Kiwi/manage.py migrate: unable to connect to DB

Kiwi version: 7.2
I am running a CentOS 8 VirtualBox on a Windows 10 host.
The basic problem seems to be that kiwi_web cannot connect to kiwi_db.
When I run the command:
docker exec -it kiwi_web /Kiwi/manage.py migrate
I get the error (full response at the end):
MySQLdb._exceptions.OperationalError: (2002, "Can't connect to MySQL server on 'db' (115)")
I also get this error if I log into kiwi_web and run "/Kiwi/manage.py migrate".
I get the same error when I run the createsuperuser command:
docker exec -it kiwi_web /Kiwi/manage.py createsuperuser
After adding mysql command line to kiwi_web, when I run:
mysql -h kiwi_db -u kiwi -p
I get the error:
ERROR 2003 (HY000): Can't connect to MySQL server on 'kiwi_db' (113)
Same error if I use different hostnames such as kiwi_db or the IP address.
I don't think I deviated from the instructions at https://kiwitcms.readthedocs.io/en/latest/installing_docker.html during the installation, except that I tried to open the Kiwi page and got the 500 internal server error before running the migrate command.
Any ideas on how to get past this?
Thanks,
..Ron
Data:
The full response when I run the command is:
# docker exec -it kiwi_web /Kiwi/manage.py migrate
Traceback (most recent call last):
File "/venv/lib/python3.6/site-packages/django/db/backends/base/base.py", line 217, in ensure_connection
self.connect()
File "/venv/lib/python3.6/site-packages/django/db/backends/base/base.py", line 195, in connect
self.connection = self.get_new_connection(conn_params)
File "/venv/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 227, in get_new_connection
return Database.connect(**conn_params)
File "/venv/lib/python3.6/site-packages/MySQLdb/__init__.py", line 84, in Connect
return Connection(*args, **kwargs)
File "/venv/lib/python3.6/site-packages/MySQLdb/connections.py", line 179, in __init__
super(Connection, self).__init__(*args, **kwargs2)
MySQLdb._exceptions.OperationalError: (2002, "Can't connect to MySQL server on 'db' (115)")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Kiwi/manage.py", line 12, in <module>
execute_from_command_line(sys.argv)
File "/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/venv/lib/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/venv/lib/python3.6/site-packages/django/core/management/base.py", line 361, in execute
self.check()
File "/venv/lib/python3.6/site-packages/django/core/management/base.py", line 390, in check
include_deployment_checks=include_deployment_checks,
File "/venv/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 64, in _run_checks
issues = run_checks(tags=[Tags.database])
File "/venv/lib/python3.6/site-packages/django/core/checks/registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "/venv/lib/python3.6/site-packages/django/core/checks/database.py", line 10, in check_database_backends
issues.extend(conn.validation.check(**kwargs))
File "/venv/lib/python3.6/site-packages/django/db/backends/mysql/validation.py", line 9, in check
issues.extend(self._check_sql_mode(**kwargs))
File "/venv/lib/python3.6/site-packages/django/db/backends/mysql/validation.py", line 13, in _check_sql_mode
with self.connection.cursor() as cursor:
File "/venv/lib/python3.6/site-packages/django/db/backends/base/base.py", line 256, in cursor
return self._cursor()
File "/venv/lib/python3.6/site-packages/django/db/backends/base/base.py", line 233, in _cursor
self.ensure_connection()
File "/venv/lib/python3.6/site-packages/django/db/backends/base/base.py", line 217, in ensure_connection
self.connect()
File "/venv/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/venv/lib/python3.6/site-packages/django/db/backends/base/base.py", line 217, in ensure_connection
self.connect()
File "/venv/lib/python3.6/site-packages/django/db/backends/base/base.py", line 195, in connect
self.connection = self.get_new_connection(conn_params)
File "/venv/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 227, in get_new_connection
return Database.connect(**conn_params)
File "/venv/lib/python3.6/site-packages/MySQLdb/__init__.py", line 84, in Connect
return Connection(*args, **kwargs)
File "/venv/lib/python3.6/site-packages/MySQLdb/connections.py", line 179, in __init__
super(Connection, self).__init__(*args, **kwargs2)
django.db.utils.OperationalError: (2002, "Can't connect to MySQL server on 'db' (115)")
And full response from createsuperuser command:
# docker exec -it kiwi_web /Kiwi/manage.py createsuperuser
Traceback (most recent call last):
File "/venv/lib/python3.6/site-packages/django/db/backends/base/base.py", line 217, in ensure_connection
self.connect()
File "/venv/lib/python3.6/site-packages/django/db/backends/base/base.py", line 195, in connect
self.connection = self.get_new_connection(conn_params)
File "/venv/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 227, in get_new_connection
return Database.connect(**conn_params)
File "/venv/lib/python3.6/site-packages/MySQLdb/__init__.py", line 84, in Connect
return Connection(*args, **kwargs)
File "/venv/lib/python3.6/site-packages/MySQLdb/connections.py", line 179, in __init__
super(Connection, self).__init__(*args, **kwargs2)
MySQLdb._exceptions.OperationalError: (2002, "Can't connect to MySQL server on 'db' (115)")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Kiwi/manage.py", line 12, in <module>
execute_from_command_line(sys.argv)
File "/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/venv/lib/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/venv/lib/python3.6/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 61, in execute
return super().execute(*args, **options)
File "/venv/lib/python3.6/site-packages/django/core/management/base.py", line 363, in execute
self.check_migrations()
File "/venv/lib/python3.6/site-packages/django/core/management/base.py", line 453, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "/venv/lib/python3.6/site-packages/django/db/migrations/executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "/venv/lib/python3.6/site-packages/django/db/migrations/loader.py", line 49, in __init__
self.build_graph()
File "/venv/lib/python3.6/site-packages/django/db/migrations/loader.py", line 212, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/venv/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 73, in applied_migrations
if self.has_table():
File "/venv/lib/python3.6/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 "/venv/lib/python3.6/site-packages/django/db/backends/base/base.py", line 256, in cursor
return self._cursor()
File "/venv/lib/python3.6/site-packages/django/db/backends/base/base.py", line 233, in _cursor
self.ensure_connection()
File "/venv/lib/python3.6/site-packages/django/db/backends/base/base.py", line 217, in ensure_connection
self.connect()
File "/venv/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/venv/lib/python3.6/site-packages/django/db/backends/base/base.py", line 217, in ensure_connection
self.connect()
File "/venv/lib/python3.6/site-packages/django/db/backends/base/base.py", line 195, in connect
self.connection = self.get_new_connection(conn_params)
File "/venv/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 227, in get_new_connection
return Database.connect(**conn_params)
File "/venv/lib/python3.6/site-packages/MySQLdb/__init__.py", line 84, in Connect
return Connection(*args, **kwargs)
File "/venv/lib/python3.6/site-packages/MySQLdb/connections.py", line 179, in __init__
super(Connection, self).__init__(*args, **kwargs2)
django.db.utils.OperationalError: (2002, "Can't connect to MySQL server on 'db' (115)")
Hello and happy new year first.
I am running a CentOS 8 VirtualBox on a Windows 10 host.
Do you mean to say that you have Docker running inside the CentOS VM or not ?
The basic problem seems to be that kiwi_web cannot connect to kiwi_db.
Assuming Docker is running inside the VM and you are trying to run the Kiwi TCMS container then:
Does docker-compose up bring the 2 containers up? Can you verify that they are present, e.g. docker ps ?
... I tried to open the Kiwi page and got the 500 internal server error before running the migrate command.
The 500 here is likely because there is no database (no tables, no connection, something else). If you were seing a Kiwi TCMS branded error page or anything at all that means kiwi_web container is running. Can you verify that this container is running ? You should be redirected to https://localhost (or FQDN, IP address) and the page should be using our own self-signed SSL certificate. Is this the case ?
Everything that you've shown looks like you've got the web container running but not the database container running ? You can try to docker exec ... /bin/bash for each of the containers to make sure they are there. If that happens then try any networking tools for Linux (e.g. ping, netstat) to see if there is a network connectivity between the two containers. They should be on the same virtual network (in Docker terms) and their names should also serve as host names on that same network.

Resources