#34298 closed New feature (wontfix)

drop constraint if exists

Reported by: sahaliyev Owned by: nobody
Component: Core (Management commands) Version: 4.1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hi there,

Today encountered a problem, where Django migrate fails to drop constraint that actually does not exists.
Here is the scenario.
I created constraint via migration and then go to db and manually drop constraint and also changed my code.
Here, new migration file is generated to drop constraint, however, constraint already dropped.
In this case, migration is giving error.
It would be great just try to drop constraint and if not exists just pass.
As PostgreSQL has this functionality, drop constraint if exists.
Django can also use this.

Change History (1)

comment:1 by Mariusz Felisiak, 22 months ago

Resolution: wontfix
Status: newclosed

Thanks for this ticket, however when you mix manual changes to your database schema and Django migrations you do it at your own risk. You can always use the --fake option to mark a migration as already applied.

It would be great just try to drop constraint and if not exists just pass.

I disagree. The migrations framework should fail loudly when it encounters an unexpected database state.

Note: See TracTickets for help on using tickets.
Back to Top