My first time posting here, sorry if this is in the wrong place.
Ive been trying to connect my django app to a database that is running on a docker container but i keep getting the following error:
(dbm) PS C:\Users\erick\Documents\python\mdb> python manage.py test
Found 10 test(s).
Creating test database for alias 'default'...
Traceback (most recent call last):
File "C:\Users\erick\Documents\python\mdb\manage.py", line 22, in <module>
main()
File "C:\Users\erick\Documents\python\mdb\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\erick\Documents\python\mdb\dbm\Lib\site-packages\django\core\management\__init__.py", line 442, in execute_from_command_line
utility.execute()
File "C:\Users\erick\Documents\python\mdb\dbm\Lib\site-packages\django\core\management\__init__.py", line 436, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\erick\Documents\python\mdb\dbm\Lib\site-packages\django\core\management\commands\test.py", line 24, in run_from_argv
super().run_from_argv(argv)
File "C:\Users\erick\Documents\python\mdb\dbm\Lib\site-packages\django\core\management\base.py", line 413, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\erick\Documents\python\mdb\dbm\Lib\site-packages\django\core\management\base.py", line 459, in execute
output = self.handle(*args, **options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\erick\Documents\python\mdb\dbm\Lib\site-packages\django\core\management\commands\test.py", line 63, in handle
failures = test_runner.run_tests(test_labels)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\erick\Documents\python\mdb\dbm\Lib\site-packages\django\test\runner.py", line 1066, in run_tests
old_config = self.setup_databases(
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\erick\Documents\python\mdb\dbm\Lib\site-packages\django\test\runner.py", line 964, in setup_databases
return _setup_databases(
^^^^^^^^^^^^^^^^^
File "C:\Users\erick\Documents\python\mdb\dbm\Lib\site-packages\django\test\utils.py", line 206, in setup_databases
connection.creation.create_test_db(
File "C:\Users\erick\Documents\python\mdb\dbm\Lib\site-packages\django\db\backends\base\creation.py", line 62, in create_test_db
self._create_test_db(verbosity, autoclobber, keepdb)
File "C:\Users\erick\Documents\python\mdb\dbm\Lib\site-packages\django\db\backends\base\creation.py", line 202, in _create_test_db
with self._nodb_cursor() as cursor:
^^^^^^^^^^^^^^^^^^^
File "C:\Users\erick\anaconda3\Lib\contextlib.py", line 137, in __enter__
return next(self.gen)
^^^^^^^^^^^^^^
File "C:\Users\erick\Documents\python\mdb\dbm\Lib\site-packages\django\db\backends\postgresql\base.py", line 507, in _nodb_cursor
with super()._nodb_cursor() as cursor:
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\erick\anaconda3\Lib\contextlib.py", line 137, in __enter__
return next(self.gen)
^^^^^^^^^^^^^^
File "C:\Users\erick\Documents\python\mdb\dbm\Lib\site-packages\django\db\backends\base\base.py", line 712, in _nodb_cursor
with conn.cursor() as cursor:
^^^^^^^^^^^^^
File "C:\Users\erick\Documents\python\mdb\dbm\Lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\erick\Documents\python\mdb\dbm\Lib\site-packages\django\db\backends\base\base.py", line 320, in cursor
return self._cursor()
^^^^^^^^^^^^^^
File "C:\Users\erick\Documents\python\mdb\dbm\Lib\site-packages\django\db\backends\base\base.py", line 296, in _cursor
self.ensure_connection()
File "C:\Users\erick\Documents\python\mdb\dbm\Lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\erick\Documents\python\mdb\dbm\Lib\site-packages\django\db\backends\base\base.py", line 279, in ensure_connection
self.connect()
File "C:\Users\erick\Documents\python\mdb\dbm\Lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\erick\Documents\python\mdb\dbm\Lib\site-packages\django\db\backends\base\base.py", line 256, in connect
self.connection = self.get_new_connection(conn_params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\erick\Documents\python\mdb\dbm\Lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\erick\Documents\python\mdb\dbm\Lib\site-packages\django\db\backends\postgresql\base.py", line 332, in get_new_connection
connection = self.Database.connect(**conn_params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\erick\Documents\python\mdb\dbm\Lib\site-packages\psycopg2\__init__.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe3 in position 58: invalid continuation byte
Ive been trying to investigate why this is happening but still dont know why. This does not happen when i use other DB that is not on a docker container.
my docker-compose.yaml file
services:
db:
image: postgres
container_name: postgres
restart: always
env_file:
- .env
volumes:
- ./dataset:/docker-entrypoint-initdb.d
ports:
- 5432:5432
.env file
POSTGRES_PASSWORD=postgres
POSTGRES_USER=postgres
POSTGRES_HOST=db
POSTGRES_DB=mdb
POSTGRES_INITDB_ARGS='--encoding=UTF-8 --lc-collate=C --lc-ctype=C'
LC_ALL=C.UTF-8
database config in settings.py
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": "mdb",
"USER": "postgres",
"PASSWORD": "postgres",
"HOST": "db",
"PORT": "5432",
}
}
Could anyone help me try to find out whats causing this? Feel free to ask for any other information i might have forgotten to include here.
Thanks in advance