[Django] #24595: alter field type on MySQL "forgets" nullability (and more)

64 views
Skip to first unread message

Django

unread,
Apr 7, 2015, 10:13:56 AM4/7/15
to django-...@googlegroups.com
#24595: alter field type on MySQL "forgets" nullability (and more)
--------------------------------+--------------------
Reporter: simonpercivall | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------
A migration changing field type on MySQL will remove "NOT NULL" (and every
other attribute) from the field. This is because MODIFY COLUMN on MySQL
requires the whole field definition to be repeated, not just the type.

So for instance:

{{{
class T(models.Model):
field = models.SmallIntegerField()
}}}

will create a table:

{{{
CREATE TABLE `app_t` (
...
`field` smallint(6) NOT NULL,
...
) ENGINE=InnoDB
}}}

Changing the field definition to:

{{{
...
field = models.IntegerField()
...
}}}

will create a migration:

{{{
...
migrations.AlterField(
model_name='t',
name='field',
field=models.IntegerField(),
)
...
}}}

resulting in the SQL

{{{
ALTER TABLE `app_t` MODIFY `field` integer
}}}

resulting in the table:

{{{
CREATE TABLE `app_t` (
...
``field` int(11) DEFAULT NULL,
...
)
}}}

This applies to 1.7 through 1.8.

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

Django

unread,
Apr 7, 2015, 10:40:17 AM4/7/15
to django-...@googlegroups.com
#24595: alter field type on MySQL "forgets" nullability (and more)
--------------------------------+--------------------------------------

Reporter: simonpercivall | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7
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 timgraham):

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


Comment:

Could you check if this is a duplicate of #23678?

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

Django

unread,
Apr 8, 2015, 12:56:08 PM4/8/15
to django-...@googlegroups.com
#24595: alter field type on MySQL "forgets" nullability (and more)
--------------------------------+--------------------------------------

Reporter: simonpercivall | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7
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 claudep):

* Attachment "24595-test.diff" added.

test failure

Django

unread,
Apr 8, 2015, 12:56:55 PM4/8/15
to django-...@googlegroups.com
#24595: alter field type on MySQL "forgets" nullability (and more)
---------------------------------+------------------------------------

Reporter: simonpercivall | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7
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 claudep):

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


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

Django

unread,
Apr 13, 2015, 3:20:58 PM4/13/15
to django-...@googlegroups.com
#24595: alter field type on MySQL "forgets" nullability (and more)
---------------------------------+------------------------------------
Reporter: simonpercivall | Owner: claudep
Type: Bug | Status: assigned
Component: Migrations | Version: 1.7

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 claudep):

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


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

Django

unread,
Apr 14, 2015, 3:42:23 AM4/14/15
to django-...@googlegroups.com
#24595: alter field type on MySQL "forgets" nullability (and more)
---------------------------------+------------------------------------
Reporter: simonpercivall | Owner:

Type: Bug | Status: new
Component: Migrations | Version: 1.7
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* owner: claudep =>
* status: assigned => new
* has_patch: 0 => 1


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

Django

unread,
Apr 14, 2015, 5:19:25 PM4/14/15
to django-...@googlegroups.com
#24595: alter field type on MySQL "forgets" nullability (and more)
-------------------------------------+-------------------------------------
Reporter: simonpercivall | Owner:

Type: Bug | Status: new
Component: Migrations | Version: 1.7
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

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

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

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/24595#comment:5>

Django

unread,
Apr 15, 2015, 2:49:53 AM4/15/15
to django-...@googlegroups.com
#24595: alter field type on MySQL "forgets" nullability (and more)
-------------------------------------+-------------------------------------
Reporter: simonpercivall | Owner:

Type: Bug | Status: new
Component: Migrations | Version: 1.7
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by claudep):

Is schema corruption bugs considered having the same severity as data loss
bugs? I'd say yes, and if it is confirmed, the patch should then also be
backported to 1.7.x. Thoughts?

--
Ticket URL: <https://code.djangoproject.com/ticket/24595#comment:6>

Django

unread,
Apr 15, 2015, 7:12:03 AM4/15/15
to django-...@googlegroups.com
#24595: alter field type on MySQL "forgets" nullability (and more)
-------------------------------------+-------------------------------------
Reporter: simonpercivall | Owner:

Type: Bug | Status: new
Component: Migrations | Version: 1.7
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by timgraham):

Okay with me.

--
Ticket URL: <https://code.djangoproject.com/ticket/24595#comment:7>

Django

unread,
Apr 17, 2015, 4:59:30 AM4/17/15
to django-...@googlegroups.com
#24595: alter field type on MySQL "forgets" nullability (and more)
-------------------------------------+-------------------------------------
Reporter: simonpercivall | Owner: Claude
| Paroz <claude@…>
Type: Bug | Status: closed
Component: Migrations | Version: 1.7
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Claude Paroz <claude@…>):

* owner: => Claude Paroz <claude@…>
* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"02260ea3f61b2fe0a0178528526101ff578c7400" 02260ea]:
{{{
#!CommitTicketReference repository=""
revision="02260ea3f61b2fe0a0178528526101ff578c7400"
Fixed #24595 -- Prevented loss of null info in MySQL field alteration

Thanks Simon Percivall for the report, and Simon Charette and Tim
Graham for the reviews.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24595#comment:8>

Django

unread,
Apr 17, 2015, 5:02:35 AM4/17/15
to django-...@googlegroups.com
#24595: alter field type on MySQL "forgets" nullability (and more)
-------------------------------------+-------------------------------------
Reporter: simonpercivall | Owner: Claude
| Paroz <claude@…>
Type: Bug | Status: closed
Component: Migrations | Version: 1.7

Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Claude Paroz <claude@…>):

In [changeset:"bbfcd9618b06556a0ae2c38456ef38bf3bea9e9d" bbfcd961]:
{{{
#!CommitTicketReference repository=""
revision="bbfcd9618b06556a0ae2c38456ef38bf3bea9e9d"
[1.8.x] Fixed #24595 -- Prevented loss of null info in MySQL field
alteration

Thanks Simon Percivall for the report, and Simon Charette and Tim
Graham for the reviews.

Backport of 02260ea3f6 from master.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24595#comment:9>

Django

unread,
Apr 17, 2015, 5:03:02 AM4/17/15
to django-...@googlegroups.com
#24595: alter field type on MySQL "forgets" nullability (and more)
-------------------------------------+-------------------------------------
Reporter: simonpercivall | Owner: Claude
| Paroz <claude@…>
Type: Bug | Status: closed
Component: Migrations | Version: 1.7

Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Claude Paroz <claude@…>):

In [changeset:"ada0845ddaefb4437e1d49aa781fd87ed9628e8f" ada0845d]:
{{{
#!CommitTicketReference repository=""
revision="ada0845ddaefb4437e1d49aa781fd87ed9628e8f"
[1.7.x] Fixed #24595 -- Prevented loss of null info in MySQL field
alteration

Thanks Simon Percivall for the report, and Simon Charette and Tim
Graham for the reviews.

Backport of 02260ea3f61b from master.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24595#comment:10>

Django

unread,
Apr 17, 2015, 12:09:36 PM4/17/15
to django-...@googlegroups.com
#24595: alter field type on MySQL "forgets" nullability (and more)
-------------------------------------+-------------------------------------
Reporter: simonpercivall | Owner: Claude
| Paroz <claude@…>
Type: Bug | Status: new
Component: Migrations | Version: 1.7
Severity: Release blocker | Resolution:

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

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


Comment:

The failures on Oracle shown in Jenkins tend to show that Oracle may also
be affected by this bug. I'll hand this over to a more knowledgeable
person, though.

--
Ticket URL: <https://code.djangoproject.com/ticket/24595#comment:11>

Django

unread,
Apr 17, 2015, 12:10:14 PM4/17/15
to django-...@googlegroups.com
#24595: alter field type on MySQL "forgets" nullability (and more)
-------------------------------------+-------------------------------------

Reporter: simonpercivall | Owner: claudep
Type: Bug | Status: assigned
Component: Migrations | Version: 1.7

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* owner: Claude Paroz <claude@…> => claudep


* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/24595#comment:12>

Django

unread,
Apr 17, 2015, 12:10:22 PM4/17/15
to django-...@googlegroups.com
#24595: alter field type on MySQL "forgets" nullability (and more)
-------------------------------------+-------------------------------------
Reporter: simonpercivall | Owner:

Type: Bug | Status: new
Component: Migrations | Version: 1.7
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* owner: claudep =>


* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/24595#comment:13>

Django

unread,
Apr 17, 2015, 12:10:46 PM4/17/15
to django-...@googlegroups.com
#24595: alter field type on MySQL "forgets" nullability (and more)
---------------------------------+------------------------------------
Reporter: simonpercivall | Owner:

Type: Bug | Status: new
Component: Migrations | Version: 1.7
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 claudep):

* has_patch: 1 => 0
* stage: Ready for checkin => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/24595#comment:14>

Django

unread,
Apr 18, 2015, 12:20:12 PM4/18/15
to django-...@googlegroups.com
#24595: alter field type on MySQL "forgets" nullability (and more)
-------------------------------------+-------------------------------------
Reporter: simonpercivall | Owner: Shai
| Berger <shai@…>
Type: Bug | Status: closed
Component: Migrations | Version: 1.7
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 Shai Berger <shai@…>):

* status: new => closed

* owner: => Shai Berger <shai@…>
* resolution: => fixed


Comment:

In [changeset:"773ec512b1872d4090b2ff8a759a85cc0f505bb9" 773ec512]:
{{{
#!CommitTicketReference repository=""
revision="773ec512b1872d4090b2ff8a759a85cc0f505bb9"
[1.7.x] Fixed #24595 Oracle test failure

The only problem for Oracle was the test, which tested nullity on
text/char fields -- but Oracle interprets_empty_strings_as_null.

Backport of d5a0acc from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24595#comment:15>

Django

unread,
Apr 18, 2015, 12:20:19 PM4/18/15
to django-...@googlegroups.com
#24595: alter field type on MySQL "forgets" nullability (and more)
-------------------------------------+-------------------------------------
Reporter: simonpercivall | Owner: Shai
| Berger <shai@…>
Type: Bug | Status: closed
Component: Migrations | Version: 1.7

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
-------------------------------------+-------------------------------------

Comment (by Shai Berger <shai@…>):

In [changeset:"8363f217f2d60e73682e791f60b7f3c07a651316" 8363f217]:
{{{
#!CommitTicketReference repository=""
revision="8363f217f2d60e73682e791f60b7f3c07a651316"
[1.8.x] Fixed #24595 Oracle test failure

The only problem for Oracle was the test, which tested nullity on
text/char fields -- but Oracle interprets_empty_strings_as_null.

Backport of d5a0acc from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24595#comment:16>

Django

unread,
Apr 18, 2015, 12:28:00 PM4/18/15
to django-...@googlegroups.com
#24595: alter field type on MySQL "forgets" nullability (and more)
-------------------------------------+-------------------------------------
Reporter: simonpercivall | Owner: Shai
| Berger <shai@…>
Type: Bug | Status: closed
Component: Migrations | Version: 1.7

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
-------------------------------------+-------------------------------------

Comment (by shaib):

Well, for some reason the commit hook missed it on master, but just to
clarify,
[changeset:"d5a0accaa090e4e65486930dbddaae5ad72aca3d" d5a0acc] fixed the
problem there.

--
Ticket URL: <https://code.djangoproject.com/ticket/24595#comment:17>

Django

unread,
Apr 18, 2015, 6:11:31 PM4/18/15
to django-...@googlegroups.com
#24595: alter field type on MySQL "forgets" nullability (and more)
-------------------------------------+-------------------------------------
Reporter: simonpercivall | Owner: Shai
| Berger <shai@…>
Type: Bug | Status: closed
Component: Migrations | Version: 1.7

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
-------------------------------------+-------------------------------------

Comment (by claudep):

Thanks Shai!

--
Ticket URL: <https://code.djangoproject.com/ticket/24595#comment:18>

Reply all
Reply to author
Forward
0 new messages