79430547

Date: 2025-02-11 15:48:31
Score: 0.5
Natty:
Report link

For me this article helped a lot: https://erthalion.info/2014/03/08/django-with-schemas/

Basically it suggest setting search_path not via DATABASES...OPTIONS, but using connection_created signal.

In my case, I created signal.py in my core app an put this code inside. This work both for migrations and basic usage.

from django.conf import settings
from django.db.backends.signals import connection_created
from django.dispatch import receiver

@receiver(connection_created)
def setup_connection(sender, connection, **kwargs):
    # Чтобы грузить данные приложения в конкретную схему.
    if connection.alias == "default":
        cursor = connection.cursor()
        cursor.execute(f'SET search_path="{settings.SEARCH_PATH}"')
Reasons:
  • Blacklisted phrase (1): this article
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: agas0077