Opened 8 weeks ago

Closed 8 weeks ago

#35624 closed Bug (invalid)

Django doesn't properly migrate IntegerField(default=0)

Reported by: bedbad Owned by:
Component: Uncategorized Version: 5.1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Steps To Reproduce:

  1. Create a model
class AModel(models.Model):
    afield = models.IntegerField()
  1. Migrate AModel into the schema
  2. Change AMode:
    class AModel(models.Model):
        afield = models.IntegerField(default=0)
    
  3. Observe the sql form of migration:
 python manage.py sqlmigrate app 0003

It will look like this:

UPDATE `app_amodel` SET `afield` = 0 WHERE `afield` IS NULL;
ALTER TABLE `app_amodel` MODIFY `afield` integer NOT NULL;

Expected Behaviour:

UPDATE `app_amodel` SET `afield` = 0 WHERE `afield` IS NULL;
ALTER TABLE `app_amodel` MODIFY `afield` integer NOT NULL DEFAULT 0;

Change History (1)

comment:1 by Simon Charette, 8 weeks ago

Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top