#24595 closed Bug (fixed)
alter field type on MySQL "forgets" nullability (and more)
Reported by: | Simon Percivall | Owned by: | |
---|---|---|---|
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)
Change History (19)
comment:1 by , 10 years ago
comment:2 by , 10 years ago
Severity: | Normal → Release blocker |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:3 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 10 years ago
Has patch: | set |
---|---|
Owner: | removed |
Status: | assigned → new |
comment:5 by , 10 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:6 by , 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?
comment:11 by , 10 years ago
Resolution: | fixed |
---|---|
Status: | closed → new |
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 , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:13 by , 10 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
comment:14 by , 10 years ago
Has patch: | unset |
---|---|
Triage Stage: | Ready for checkin → Accepted |
comment:17 by , 10 years ago
Well, for some reason the commit hook missed it on master, but just to clarify,
d5a0acc fixed the problem there.
Could you check if this is a duplicate of #23678?