#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. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/057.db9759e84418355130fa5a91729be2e3%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.