Renaming a model field that has null=False makes it nullable in MySQL
Steps to reproduce:
- Create a simple model:
class TestModel(models.Model):
value_a = models.IntegerField(null=False)
- ./manage.py makemigrations
- ./manage.py migrate
- So far so good:
mysql> describe testy_testmodel;
+---------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+---------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| value_a | int(11) | NO | | NULL | |
+---------+---------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
- Change model field name value_a -> value_b:
class TestModel(models.model):
value_b = models.IntegerField(null=False)
- ./manage.py makemigrations
- ./manage.py migrate
- NOT NULL for value_b has been lost:
mysql> describe testy_testmodel;
+---------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+---------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| value_b | int(11) | YES | | NULL | |
+---------+---------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
The ALTER-statement django produces is
ALTER TABLE `testy_testmodel` CHANGE `value_a` `value_b` integer;
...and it should contain the NOT NULL, but it doesn't.
Edit: Similar bug when changing field type was fixed in #24595. The bug is still present in 1.8.1 when renaming a field.
Description: |
modified (diff)
|
Resolution: |
→ duplicate
|
Status: |
new → closed
|
Description: |
modified (diff)
|
Resolution: |
duplicate
|
Status: |
closed → new
|
Severity: |
Normal → Release blocker
|
Triage Stage: |
Unreviewed → Accepted
|
Has patch: |
set
|
Owner: |
changed from nobody to Andriy Sokolovskiy
|
Status: |
new → assigned
|
Triage Stage: |
Accepted → Ready for checkin
|
Resolution: |
→ fixed
|
Status: |
assigned → closed
|
This looks like a duplicate of #24595, which is fixed in 1.7.8 and 1.8.1.