From 7a47ca4058976814f59fc9ec62904973f116f411 Mon Sep 17 00:00:00 2001 From: amitrana01 Date: Thu, 11 Sep 2025 18:39:00 +0530 Subject: [PATCH] Fix django_site relation error by adding Site configuration - Add configure_site management command to create Django Site object - Configure site domain as dt.netcoptech.com during startup (like quantum-digital) - Update both compose files to run configure_site after migrations - This fixes the 'relation django_site does not exist' error on /accounts/login/ Django Allauth requires a Site object to work properly. --- .../management/commands/configure_site.py | 44 +++++++++++++++++++ docker-compose.dokploy-external-db.yml | 1 + docker-compose.dokploy-simple.yml | 1 + 3 files changed, 46 insertions(+) create mode 100644 apps/core/management/commands/configure_site.py diff --git a/apps/core/management/commands/configure_site.py b/apps/core/management/commands/configure_site.py new file mode 100644 index 0000000..7a6d350 --- /dev/null +++ b/apps/core/management/commands/configure_site.py @@ -0,0 +1,44 @@ +from django.core.management.base import BaseCommand +from django.contrib.sites.models import Site +from django.conf import settings + + +class Command(BaseCommand): + help = 'Configure Django Site for production domain' + + def add_arguments(self, parser): + parser.add_argument( + '--domain', + type=str, + default='dt.netcoptech.com', + help='Domain name for the site', + ) + parser.add_argument( + '--name', + type=str, + default='Django Template', + help='Display name for the site', + ) + + def handle(self, *args, **options): + domain = options['domain'] + name = options['name'] + + # Get or create the default site (pk=1) + site, created = Site.objects.get_or_create(pk=1) + site.domain = domain + site.name = name + site.save() + + if created: + self.stdout.write( + self.style.SUCCESS(f'✅ Created new site: {name} ({domain})') + ) + else: + self.stdout.write( + self.style.SUCCESS(f'✅ Updated existing site: {name} ({domain})') + ) + + self.stdout.write( + self.style.SUCCESS('Site configuration completed successfully!') + ) diff --git a/docker-compose.dokploy-external-db.yml b/docker-compose.dokploy-external-db.yml index 33c6470..f0f9afb 100644 --- a/docker-compose.dokploy-external-db.yml +++ b/docker-compose.dokploy-external-db.yml @@ -17,5 +17,6 @@ services: sh -c "python manage.py migrate && python manage.py create_groups && python manage.py setup_social_apps && + python manage.py configure_site --domain=dt.netcoptech.com --name='Django Template' && python manage.py collectstatic --noinput && gunicorn --bind 0.0.0.0:8000 --workers 3 --timeout 120 django_project.wsgi:application" diff --git a/docker-compose.dokploy-simple.yml b/docker-compose.dokploy-simple.yml index 5131c9a..d8ad5ef 100644 --- a/docker-compose.dokploy-simple.yml +++ b/docker-compose.dokploy-simple.yml @@ -39,5 +39,6 @@ networks: sh -c "python manage.py migrate && python manage.py create_groups && python manage.py setup_social_apps && + python manage.py configure_site --domain=dt.netcoptech.com --name='Django Template' && python manage.py collectstatic --noinput && gunicorn --bind 0.0.0.0:8000 --workers 3 --timeout 120 django_project.wsgi:application"