#30741: Setting db_constraint=False to an existing column does not properly drop
the constraint
-------------------------------------+-------------------------------------
Reporter: ses4j | Owner: nobody
Type: | Status: new
Uncategorized |
Component: | Version: 2.2
Migrations | Keywords: db_constraint,
Severity: Normal | migrations
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Repro steps, using PostgreSQL and Django 2.2.4:
1. Create a new model with a normal, constrained ForeignKey, such as:
{{{
class Child(models.Model):
parent = models.ForeignKey('myapp.Parent', related_name="+",
on_delete=models.DO_NOTHING)
}}}
2. Create a migration: python manage.py makemigrations
3. Add db_constraint=False, like so:
{{{
class Child(models.Model):
parent = models.ForeignKey('myapp.Parent', related_name="+",
on_delete=models.DO_NOTHING, db_constraint=False)
}}}
4. Create a second migration: python manage.py makemigrations
5. Peep at the generated SQL. The first migration creates the constraint,
and the second fails to remove it:
{{{
(.env) c:\wc\dbconstraintnotdropped>python manage.py sqlmigrate myapp 0001
BEGIN;
--
-- Create model Parent
--
CREATE TABLE "myapp_parent" ("id" serial NOT NULL PRIMARY KEY);
--
-- Create model Child
--
CREATE TABLE "myapp_child" ("id" serial NOT NULL PRIMARY KEY, "parent_id"
integer NOT NULL);
ALTER TABLE "myapp_child" ADD CONSTRAINT
"myapp_child_parent_id_af46d0ab_fk_myapp_parent_id" FOREIGN KEY
("parent_id") REFERENCES "myapp_parent" ("id") DEFERRABLE INITIALLY
DEFERRED;
CREATE INDEX "myapp_child_parent_id_af46d0ab" ON "myapp_child"
("parent_id");
COMMIT;
(.env) c:\wc\dbconstraintnotdropped>python manage.py sqlmigrate myapp 0002
BEGIN;
--
-- Alter field submission on child
--
COMMIT;
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30741>
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/048.4e61b43a758802961765c0fdf193086b%40djangoproject.com.