[Django] #23264: db_constraint=False not enforced on migrations

39 views
Skip to first unread message

Django

unread,
Aug 8, 2014, 10:28:03 PM8/8/14
to django-...@googlegroups.com
#23264: db_constraint=False not enforced on migrations
----------------------------+----------------------
Reporter: jmacul2 | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7-rc-2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+----------------------
When adding db_constraint=False on a ForeignKey or directly on a Migration
still causes the constraint to be created.

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

Django

unread,
Aug 8, 2014, 10:36:08 PM8/8/14
to django-...@googlegroups.com
#23264: db_constraint=False not enforced on migrations
----------------------------+--------------------------------------

Reporter: jmacul2 | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7-rc-2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Changes (by jmacul2):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Example...

foo/models.py

{{{
from django.db import models

class Car(models.Model):
name = models.CharField(max_length=255)
color = models.ForeignKey('Color', db_constrain=False)

class Color(models.Model):
color = models.CharField(max_length=255)
}}}

foo/migrations/0001_initial.py

{{{
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
]

operations = [
migrations.CreateModel(
name='Car',
fields=[
('id', models.AutoField(verbose_name='ID',
serialize=False, auto_created=True, primary_key=True)),
('name', models.CharField(max_length=255)),
],
options={
},
bases=(models.Model,),
),
migrations.CreateModel(
name='Color',
fields=[
('id', models.AutoField(verbose_name='ID',
serialize=False, auto_created=True, primary_key=True)),
('color', models.CharField(max_length=255)),
],
options={
},
bases=(models.Model,),
),
migrations.AddField(
model_name='car',
name='color',
field=models.ForeignKey(to='foo.Color', db_constraint=False),
preserve_default=True,
),
]
}}}

/manage.py sqlmigrate foo 0001

{{{

CREATE TABLE "foo_car" ("id" serial NOT NULL PRIMARY KEY, "name"
varchar(255) NOT NULL);
CREATE TABLE "foo_color" ("id" serial NOT NULL PRIMARY KEY, "color"
varchar(255) NOT NULL);
ALTER TABLE "foo_car" ADD COLUMN "color_id" integer NOT NULL;
ALTER TABLE "foo_car" ALTER COLUMN "color_id" DROP DEFAULT;
CREATE INDEX foo_car_399a0583 ON "foo_car" ("color_id");
ALTER TABLE "foo_car" ADD CONSTRAINT
foo_car_color_id_75af12d643db05a2_fk_foo_color_id FOREIGN KEY ("color_id")
REFERENCES "foo_color" ("id") DEFERRABLE INITIALLY DEFERRED;

}}}

FYI - This is using postgres

--
Ticket URL: <https://code.djangoproject.com/ticket/23264#comment:1>

Django

unread,
Aug 9, 2014, 2:59:18 AM8/9/14
to django-...@googlegroups.com
#23264: db_constraint=False not enforced on migrations
---------------------------------+------------------------------------

Reporter: jmacul2 | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7-rc-2
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by bmispelon):

* severity: Normal => Release blocker
* stage: Unreviewed => Accepted


Comment:

Hi,

Indeed, the constraint seems to be created regardless of the
`db_constraint=False`.
Note that the same bux exists for `ManyToManyField.db_constraint`.

I'll bump the ticket to the `release blocker` status too.

Thanks.

--
Ticket URL: <https://code.djangoproject.com/ticket/23264#comment:2>

Django

unread,
Aug 9, 2014, 3:10:20 AM8/9/14
to django-...@googlegroups.com
#23264: db_constraint=False not enforced on migrations
---------------------------------+----------------------------------------
Reporter: jmacul2 | Owner: andrewgodwin
Type: Bug | Status: assigned
Component: Migrations | Version: 1.7-rc-2

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+----------------------------------------
Changes (by andrewgodwin):

* owner: nobody => andrewgodwin
* status: new => assigned


Comment:

Ah, I didn't even know we had db_constraint! Adding now.

--
Ticket URL: <https://code.djangoproject.com/ticket/23264#comment:3>

Django

unread,
Aug 9, 2014, 3:51:34 AM8/9/14
to django-...@googlegroups.com
#23264: db_constraint=False not enforced on migrations
---------------------------------+----------------------------------------
Reporter: jmacul2 | Owner: andrewgodwin
Type: Bug | Status: closed
Component: Migrations | Version: 1.7-rc-2
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+----------------------------------------
Changes (by Andrew Godwin <andrew@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"ee74f9fe3bcd8c2648e4623d5929fceac851b97f"]:
{{{
#!CommitTicketReference repository=""
revision="ee74f9fe3bcd8c2648e4623d5929fceac851b97f"
[1.7.x] Fixed #23264: Schema backends honour db_constraint
}}}

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

Reply all
Reply to author
Forward
0 new messages