티스토리 수익 글 보기
The web framework for perfectionists with deadlines.
Issues
#24817 closed Bug (fixed)
Renaming a model field that has null=False makes it nullable in MySQL
| Reported by: | murfi | Owned by: | Andriy Sokolovskiy |
|---|---|---|---|
| Component: | Migrations | Version: | 1.8 |
| Severity: | Release blocker | Keywords: | |
| Cc: | alasdair@…, me@… | Triage Stage: | Ready for checkin |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by murfi)
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.
Attachments (1)
- ticket_24817.patch (2.3 KB ) – added by Andriy Sokolovskiy 11 years ago.
- Test to reproduce the issue
Download all attachments as: .zip
Change History (16)
comment:1 by murfi, 11 years ago
| Description: | modified (diff) |
|---|
comment:2 by Alasdair Nicol, 11 years ago
| Resolution: | → duplicate |
|---|---|
| Status: | new → closed |
comment:3 by Alasdair Nicol, 11 years ago
| Cc: | alasdair@… added |
|---|
comment:4 by murfi, 11 years ago
| Description: | modified (diff) |
|---|---|
| Resolution: | duplicate |
| Status: | closed → new |
comment:5 by murfi, 11 years ago
True the comment in the end related to changing field type was invalid and fixed in #24595. The example case is still reproducible with Django==1.8.1.
comment:6 by Alasdair Nicol, 11 years ago
| Severity: | Normal → Release blocker |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
Apologies for incorrectly closing as a duplicate before. I can reproduce in Django 1.7.8, 1.8.1 and master.
by Andriy Sokolovskiy, 11 years ago
| Attachment: | ticket_24817.patch added |
|---|
Test to reproduce the issue
comment:8 by Andriy Sokolovskiy, 11 years ago
| Cc: | me@… added |
|---|
I just attached a patch with tests which reproduces the issue.
I’m also working on fixing issue
comment:9 by Andriy Sokolovskiy, 11 years ago
| Has patch: | set |
|---|---|
| Owner: | changed from nobody to Andriy Sokolovskiy |
| Status: | new → assigned |
comment:10 by Andriy Sokolovskiy, 11 years ago
PR against master – https://github.com/django/django/pull/4715
comment:11 by Tim Graham, 11 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
Claude, look good to you?
comment:13 by Tim Graham <timograham@…>, 11 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
comment:14 by Tim Graham <timograham@…>, 11 years ago
In f65d4db:
[1.8.x] Fixed #24817 — Prevented loss of null info in MySQL field renaming.
Backport of 80ad5472ce4b6ba6e94227422d0727371e97cdf0 from master
comment:15 by Tim Graham <timograham@…>, 11 years ago
In 927d90ee:
[1.7.x] Fixed #24817 — Prevented loss of null info in MySQL field renaming.
Backport of 80ad5472ce4b6ba6e94227422d0727371e97cdf0 from master
Download in other formats:
Django Links
Learn More
Get Involved
Follow Us
- Hosting by In-kind donors
- Design by Threespot &
© 2005-2026 Django Software Foundation unless otherwise noted. Django is a registered trademark of the Django Software Foundation.
This looks like a duplicate of #24595, which is fixed in 1.7.8 and 1.8.1.