#36598: Django migrations is unable to find remove constraints from non-public
schema for Postgres
-------------------------------------+-------------------------------------
     Reporter:  Salaah Amin          |                    Owner:  (none)
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  4.2
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  postgres, db, orm    |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Comment (by Salaah Amin):

 Hi Tanishq,
 I don't think that would work.
 In fact, I ran two queries:

 {{{

 SELECT
         c.conname,
         array(
                 SELECT attname
                 FROM unnest(c.conkey) WITH ORDINALITY cols(colid, arridx)
                 JOIN pg_attribute AS ca ON cols.colid = ca.attnum
                 WHERE ca.attrelid = c.conrelid
                 ORDER BY cols.arridx
         ),
         c.contype,
         (SELECT fkc.relname || '.' || fka.attname
         FROM pg_attribute AS fka
         JOIN pg_class AS fkc ON fka.attrelid = fkc.oid
         WHERE fka.attrelid = c.confrelid AND fka.attnum = c.confkey[1]),
         cl.reloptions
 FROM pg_constraint AS c
 JOIN pg_class AS cl ON c.conrelid = cl.oid
 WHERE cl.relname like '%occupancy' AND
 pg_catalog.pg_table_is_visible(cl.oid);
 }}}

 Here I kept the pg_table_is_visible constraint in and it didn't return
 anything.

 However, it works when I run:

 {{{
 SELECT
         c.conname,
         array(
                 SELECT attname
                 FROM unnest(c.conkey) WITH ORDINALITY cols(colid, arridx)
                 JOIN pg_attribute AS ca ON cols.colid = ca.attnum
                 WHERE ca.attrelid = c.conrelid
                 ORDER BY cols.arridx
         ),
         c.contype,
         (SELECT fkc.relname || '.' || fka.attname
         FROM pg_attribute AS fka
         JOIN pg_class AS fkc ON fka.attrelid = fkc.oid
         WHERE fka.attrelid = c.confrelid AND fka.attnum = c.confkey[1]),
         cl.reloptions
 FROM pg_constraint AS c
 JOIN pg_class AS cl ON c.conrelid = cl.oid
 WHERE cl.relname like '%occupancy';
 }}}

 So the issue really is pg_table_is_visible.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36598#comment:3>
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 visit 
https://groups.google.com/d/msgid/django-updates/010701993a56ac7e-bacdbd6b-4733-4c43-b333-b3470030966c-000000%40eu-central-1.amazonses.com.

Reply via email to