﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
24595	"alter field type on MySQL ""forgets"" nullability (and more)"	Simon Percivall	Shai Berger <shai@…>	"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."	Bug	closed	Migrations	1.7	Release blocker	fixed			Accepted	0	0	0	0	0	0
