#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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.f98566b13b8311722b0432a67e0219f9%40djangoproject.com.

Reply via email to