Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#24595 closed Bug (fixed)

alter field type on MySQL "forgets" nullability (and more)

Reported by: Simon Percivall Owned by: Shai Berger <shai@…>
Component: Migrations Version: 1.7
Severity: Release blocker Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Attachments (1)

24595-test.diff (1.1 KB ) - added by Claude Paroz 10 years ago.
test failure

Download all attachments as: .zip

Change History (19)

comment:1 by Tim Graham, 10 years ago

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

by Claude Paroz, 10 years ago

Attachment: 24595-test.diff added

test failure

comment:2 by Claude Paroz, 10 years ago

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted

comment:3 by Claude Paroz, 10 years ago

Owner: changed from nobody to Claude Paroz
Status: newassigned

comment:4 by Claude Paroz, 10 years ago

Has patch: set
Owner: Claude Paroz removed
Status: assignednew

comment:5 by Simon Charette, 10 years ago

Triage Stage: AcceptedReady for checkin

comment:6 by Claude Paroz, 10 years ago

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?

Version 0, edited 10 years ago by Claude Paroz (next)

comment:7 by Tim Graham, 10 years ago

Okay with me.

comment:8 by Claude Paroz <claude@…>, 10 years ago

Owner: set to Claude Paroz <claude@…>
Resolution: fixed
Status: newclosed

In 02260ea:

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.

comment:9 by Claude Paroz <claude@…>, 10 years ago

In bbfcd961:

[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.

comment:10 by Claude Paroz <claude@…>, 10 years ago

In ada0845d:

[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.

comment:11 by Claude Paroz, 10 years ago

Resolution: fixed
Status: closednew

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.

comment:12 by Claude Paroz, 10 years ago

Owner: changed from Claude Paroz <claude@…> to Claude Paroz
Status: newassigned

comment:13 by Claude Paroz, 10 years ago

Owner: Claude Paroz removed
Status: assignednew

comment:14 by Claude Paroz, 10 years ago

Has patch: unset
Triage Stage: Ready for checkinAccepted

comment:15 by Shai Berger <shai@…>, 10 years ago

Owner: set to Shai Berger <shai@…>
Resolution: fixed
Status: newclosed

In 773ec512:

[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

comment:16 by Shai Berger <shai@…>, 10 years ago

In 8363f217:

[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

comment:17 by Shai Berger, 10 years ago

Well, for some reason the commit hook missed it on master, but just to clarify,
d5a0acc fixed the problem there.

comment:18 by Claude Paroz, 10 years ago

Thanks Shai!

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