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}"')