Re: [Django] #33673: PostgreSQL removes constraints when removing columns.

4 views
Skip to first unread message

Django

unread,
May 3, 2022, 8:33:27 AM5/3/22
to django-...@googlegroups.com
#33673: PostgreSQL removes constraints when removing columns.
----------------------------+--------------------------------------
Reporter: George | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 3.2
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------

Comment (by George):

Replying to [comment:2 Mariusz Felisiak]:
> Thanks for the report, however PostgreSQL silently drops constraints,
not Django itself. Unfortunately when you create migrations manually you
must be aware of database-specific behavior and handle them on your own in
most of cases. As far as I'm aware described use case (removing column to
add it immediately in the same migration) is really unusual and not worth
additional complexity and a performance regression for all users. Noticing
that constraint is missing would require inspecting db constraints which
is always quite expensive.
>
> Is there any reason you cannot handle this automatically with
`AlterField()`?

No particular reason, no, and in this case I agree the issue is we had a
poorly written manual migration, fault is on us. I just wanted to make
sure this is indeed the behavior.

Out of curiosity, does django inspect the database at all for migrations
or is it 100% looking at the mdoel's code and comparing it with the code
from all previous migrations?

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

Django

unread,
May 3, 2022, 9:04:22 AM5/3/22
to django-...@googlegroups.com
#33673: PostgreSQL removes constraints when removing columns.
----------------------------+--------------------------------------
Reporter: George | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 3.2
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------

Comment (by Mariusz Felisiak):

Replying to [comment:3 George]:


> Out of curiosity, does django inspect the database at all for migrations
or is it 100% looking at the mdoel's code and comparing it with the code
from all previous migrations?

Django migrations inspects database in many places, but all of them slow
things down and this scenario is so specific that IMO it's not worth
additional guard.

--
Ticket URL: <https://code.djangoproject.com/ticket/33673#comment:4>

Reply all
Reply to author
Forward
0 new messages