horilla
horilla copied to clipboard
Cannot connect to Postgres Db running inn docker container
Bug Report
Description
Cannot run migrations after doing settings related to postgres DB in your project. The error looks something like this
File "/home/aditya/github/django_projects/venv/lib/python3.10/site-packages/django/db/migrations/recorder.py", line 72, in ensure_schema
raise MigrationSchemaMissing(
django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the django_migrations table (no schema has been selected to create in
LINE 1: CREATE TABLE "django_migrations" ("id" bigint NOT NULL PRIMA...
^
)
Steps to Reproduce
- Add settings realated to postgres Db here in settings.py file
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': 'pass123',
'HOST': '172.17.0.2', # PostgreSQL container IP address
'PORT': '5432', # Default PostgreSQL port
}
}
- My Docker container realted details:
{"bridge":{"IPAMConfig":null,"Links":null,"Aliases":null,"MacAddress":"02:42:ac:11:00:02","NetworkID":"dcb4fdd2094900942a627288e2f5558eabbf48192a42b2eea2f6b6965b33eb16","EndpointID":"fccae3bdfd2e3eb91e207ec7a9bb26390635509ce4c17d45e1edba47b0f6e294","Gateway":"172.17.0.1","IPAddress":"172.17.0.2","IPPrefixLen":16,"IPv6Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"DriverOpts":null,"DNSNames":null}}
My docker container conatining postgres DB port number:
As you can see the portnumber it's using is 5432
The error I am getting is : Cannot run migrations after doing settings related to postgres DB in your project. The error looks something like this
File "/home/aditya/github/django_projects/venv/lib/python3.10/site-packages/django/db/migrations/recorder.py", line 72, in ensure_schema
raise MigrationSchemaMissing(
django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the django_migrations table (no schema has been selected to create in
LINE 1: CREATE TABLE "django_migrations" ("id" bigint NOT NULL PRIMA...
^
)
Expected Behavior
The migrate command should have been able to create tables in my posgres db using the credentials NOTE: I was able to connect to the postgres container in docker in my different django project using the same credentials.
Environment
- Django Version: [4.2.1]
- Python Version: [3.10.12]
- Operating System: [Ubuntu 22.04]
- Browser: [Chrome] @horilla-opensource I humbly ask you to please have a look into it
Hi @aryan68125 , We'll look into it and get back to you asap.
With Regards, Team Horilla
Hi @aryan68125 , We'll look into it and get back to you asap.
With Regards, Team Horilla
An update regarding this issue :
One of the possible solution to this problem that I found-->
I deleted the existing postgres container using thi command docker rm -f < Container_ID>
and then re-created a postgres container using this command :
docker run -d --name postgresCont -p 5432:5432 -e POSTGRES_PASSWORD=pass123 postgres
and then I fetch the ip address of postgres SQL running inside this container using this command
sudo docker inspect postgresCont -f "{{json .NetworkSettings.Networks }}"
Now the project seems to have created some tables but in the middle of it I got some errors here is the releveant stck trace that I am providing below :
(venv) venvaditya@aditya-MacBookAir:~/github/django_projects/django_project/HRM/horilla$ python3 manage.py migrate
Operations to perform:
Apply all migrations: admin, asset, attendance, auth, base, contenttypes, django_apscheduler, employee, helpdesk, horilla_audit, horilla_documents, leave, notifications, offboarding, onboarding, payroll, pms, recruitment, sessions
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying admin.0003_logentry_add_action_flag_choices... OK
Applying horilla_audit.0001_initial... OK
Applying base.0001_initial... OK
Applying employee.0001_initial... OK
Applying asset.0001_initial... OK
Applying asset.0002_initial...Job "leave_reset (trigger: interval[0:00:10], next run at: 2024-04-16 13:38:38 IST)" raised an exception
Traceback (most recent call last):
File "/home/aditya/github/django_projects/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute
return self.cursor.execute(sql, params)
psycopg2.errors.UndefinedTable: relation "leave_leavetype" does not exist
LINE 1: ..._holiday", "leave_leavetype"."company_id_id" FROM "leave_lea...
^
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/aditya/github/django_projects/venv/lib/python3.10/site-packages/apscheduler/executors/base.py", line 125, in run_job
retval = job.func(*job.args, **job.kwargs)
File "/home/aditya/github/django_projects/django_project/HRM/horilla/leave/scheduler.py", line 16, in leave_reset
for leave_type in leave_types:
File "/home/aditya/github/django_projects/venv/lib/python3.10/site-packages/django/db/models/query.py", line 398, in __iter__
self._fetch_all()
File "/home/aditya/github/django_projects/venv/lib/python3.10/site-packages/django/db/models/query.py", line 1881, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/home/aditya/github/django_projects/venv/lib/python3.10/site-packages/django/db/models/query.py", line 91, in __iter__
results = compiler.execute_sql(
File "/home/aditya/github/django_projects/venv/lib/python3.10/site-packages/django/db/models/sql/compiler.py", line 1562, in execute_sql
cursor.execute(sql, params)
File "/home/aditya/github/django_projects/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 102, in execute
return super().execute(sql, params)
File "/home/aditya/github/django_projects/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 67, in execute
return self._execute_with_wrappers(
File "/home/aditya/github/django_projects/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/aditya/github/django_projects/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 84, in _execute
with self.db.wrap_database_errors:
File "/home/aditya/github/django_projects/venv/lib/python3.10/site-packages/django/db/utils.py", line 91, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/aditya/github/django_projects/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "leave_leavetype" does not exist
LINE 1: ..._holiday", "leave_leavetype"."company_id_id" FROM "leave_lea...
^
Job "recurring_holiday (trigger: interval[0:00:10], next run at: 2024-04-16 13:38:38 IST)" raised an exception
Traceback (most recent call last):
File "/home/aditya/github/django_projects/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute
return self.cursor.execute(sql, params)
psycopg2.errors.UndefinedTable: relation "leave_holiday" does not exist
LINE 1: ..."recurring", "leave_holiday"."company_id_id" FROM "leave_hol...
^
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/aditya/github/django_projects/venv/lib/python3.10/site-packages/apscheduler/executors/base.py", line 125, in run_job
retval = job.func(*job.args, **job.kwargs)
File "/home/aditya/github/django_projects/django_project/HRM/horilla/leave/scheduler.py", line 44, in recurring_holiday
for recurring_holiday in recurring_holidays:
File "/home/aditya/github/django_projects/venv/lib/python3.10/site-packages/django/db/models/query.py", line 398, in __iter__
self._fetch_all()
File "/home/aditya/github/django_projects/venv/lib/python3.10/site-packages/django/db/models/query.py", line 1881, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/home/aditya/github/django_projects/venv/lib/python3.10/site-packages/django/db/models/query.py", line 91, in __iter__
results = compiler.execute_sql(
File "/home/aditya/github/django_projects/venv/lib/python3.10/site-packages/django/db/models/sql/compiler.py", line 1562, in execute_sql
cursor.execute(sql, params)
File "/home/aditya/github/django_projects/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 102, in execute
return super().execute(sql, params)
File "/home/aditya/github/django_projects/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 67, in execute
return self._execute_with_wrappers(
File "/home/aditya/github/django_projects/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/aditya/github/django_projects/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 84, in _execute
with self.db.wrap_database_errors:
File "/home/aditya/github/django_projects/venv/lib/python3.10/site-packages/django/db/utils.py", line 91, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/aditya/github/django_projects/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "leave_holiday" does not exist
LINE 1: ..."recurring", "leave_holiday"."company_id_id" FROM "leave_hol...
^
OK
Applying leave.0001_initial... OK
Applying attendance.0001_initial... OK
Applying attendance.0002_initial... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying auth.0008_alter_user_username_max_length... OK
Applying auth.0009_alter_user_last_name_max_length... OK
Applying auth.0010_alter_group_name_max_length... OK
Applying auth.0011_update_proxy_permissions... OK
Applying auth.0012_alter_user_first_name_max_length... OK
Applying base.0002_initial... OK
Applying django_apscheduler.0001_initial... OK
Applying django_apscheduler.0002_auto_20180412_0758... OK
Applying django_apscheduler.0003_auto_20200716_1632... OK
Applying django_apscheduler.0004_auto_20200717_1043... OK
Applying django_apscheduler.0005_migrate_name_to_id... OK
Applying django_apscheduler.0006_remove_djangojob_name... OK
Applying django_apscheduler.0007_auto_20200717_1404... OK
Applying django_apscheduler.0008_remove_djangojobexecution_started... OK
Applying django_apscheduler.0009_djangojobexecution_unique_job_executions... OK
Applying helpdesk.0001_initial... OK
Applying horilla_documents.0001_initial... OK
Applying notifications.0001_initial... OK
Applying offboarding.0001_initial... OK
Applying recruitment.0001_initial... OK
Applying onboarding.0001_initial... OK
Applying payroll.0001_initial... OK
Applying pms.0001_initial... OK
Applying sessions.0001_initial... OK
Please have a look into this I hope this helps you in retifying the issue @horilla-opensource Again thank you very much for looking into issues and solving it.
Thanks for the update. The team is looking into this and will get back to you.
With Regards, Team Horilla
Hi @aryan68125 , Can you please try it out with the latest code?
With Regards, Team Horilla
@horilla-opensource yes sir i would gladly look into your code ... I am closely following your open source project . But I am facing some difficulty in understanding your code . I wonder when I will get a chance to contribute in this project. I am doing what I can to help you however I can
Hi @aryan68125 , Can we know the area in which you are facing the difficulty? We are happy to guide you in all possible ways.
With Regards, Team Horilla
Hi @aryan68125 , Were you able to check it out?
With Regards, Team Horilla
Hi @aryan68125 , Any updates?
With Regards, Team Horilla
Hi @aryan68125 , We are closing this issue due to inactivity. It seems that there hasn't been any recent activity or discussion, and we believe it may have been resolved or is no longer relevant. If you feel this issue is still important and should be addressed, please feel free to reopen it or create a new issue with updated details.
With Regards, Team Horilla