#24817: Renaming a model field that has null=False makes it nullable in MySQL
----------------------------+--------------------------------------
     Reporter:  murfi       |                    Owner:  nobody
         Type:  Bug         |                   Status:  new
    Component:  Migrations  |                  Version:  1.8
     Severity:  Normal      |               Resolution:
     Keywords:              |             Triage Stage:  Unreviewed
    Has patch:  0           |      Needs documentation:  0
  Needs tests:  0           |  Patch needs improvement:  0
Easy pickings:  0           |                    UI/UX:  0
----------------------------+--------------------------------------
Changes (by murfi):

 * needs_better_patch:   => 0
 * needs_tests:   => 0
 * needs_docs:   => 0


Old description:

> Steps to reproduce:
>
> 1. Create a simple model:
> {{{
> class TestModel(models.Model):
>         value_a = models.IntegerField(null=False)
> }}}
> 2. '''./manage.py makemigrations'''
> 3. '''./manage.py migrate'''
> 4. 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)
> }}}
> 5. Change model field name '''value_a''' -> '''value_b''':
> {{{
> class TestModel(models.model):
>         value_b = models.IntegerField(null=False)
> }}}
> 6. '''./manage.py makemigrations'''
> 7. '''./manage.py migrate'''
> 8. '''NOT NULL''' for '''value_b''' has bee 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.
>
> This affects other '''ALTER TABLE'''-statements too, e.g. if changing
> field type from''' IntegerField''' to '''BigIntergerField'''. The bug is
> present in 1.7 as well.

New description:

 Steps to reproduce:

 1. Create a simple model:
 {{{
 class TestModel(models.Model):
         value_a = models.IntegerField(null=False)
 }}}
 2. '''./manage.py makemigrations'''
 3. '''./manage.py migrate'''
 4. 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)
 }}}
 5. Change model field name '''value_a''' -> '''value_b''':
 {{{
 class TestModel(models.model):
         value_b = models.IntegerField(null=False)
 }}}
 6. '''./manage.py makemigrations'''
 7. '''./manage.py migrate'''
 8. '''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.

 This affects other '''ALTER TABLE'''-statements too, e.g. if changing
 field type from''' IntegerField''' to '''BigIntergerField'''. The bug is
 present in 1.7 as well.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/24817#comment:1>
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/063.2e2baa7c806474d2bdfe638a1d88aaf1%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to