[Django] #32495: Migrations that modify constraints raise an exception on multi-schema databases

8 views
Skip to first unread message

Django

unread,
Mar 2, 2021, 5:14:04 AM3/2/21
to django-...@googlegroups.com
#32495: Migrations that modify constraints raise an exception on multi-schema
databases
-----------------------------------------+------------------------
Reporter: Chris Spencer | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 3.1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
I have a multi-tenant Django application with a PostgreSQL backend that
separates user data using uniquely named schemas. Each tenant has a
separate front-end website and settings file, specifying their unique
database connection parameters. The schema structures are identical and
are managed and migrated the same way.

I'm finding this setup is not fully supported by Django, in that I'm
unable to migrate any changes to indexes or constraints.

The query that retrieves the old SQL object to update
(django.db.backends.postgresql.introspection.DatabaseIntrospection.get_constraints)
retrieves any object matching the name. The problem is that it's able to
see across any schema the current user has access to, and not just the
current schema being migrated, resulting in an error like:

ValueError: Found wrong number (7) of constraints for
myapp_mytable(col1, col2, col3)

i.e. This error would be thrown if I had 7 schemas on a database, all
containing the same constraint, and I tried to migrate one of the schemas.

I've been able to work around this issue by monkey patching the
get_constraints method using a variation of my submitted patch
(https://github.com/django/django/pull/14067), which just updates the
query to filter by the current schema.

--
Ticket URL: <https://code.djangoproject.com/ticket/32495>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 2, 2021, 5:26:06 AM3/2/21
to django-...@googlegroups.com
#32495: Migrations that modify constraints raise an exception on multi-schema
databases
-------------------------------+--------------------------------------

Reporter: Chris Spencer | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 3.1
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => duplicate


Comment:

> I'm finding this setup is not fully supported by Django, in that I'm
unable to migrate any changes to indexes or constraints.

Yes it's not supported, official support for database schemas is discussed
in #6148.

--
Ticket URL: <https://code.djangoproject.com/ticket/32495#comment:1>

Reply all
Reply to author
Forward
0 new messages