#28980: Django doesn't check the type of one-off value
----------------------------------------+------------------------
               Reporter:  Nikos Katsos  |          Owner:  nobody
                   Type:  Bug           |         Status:  new
              Component:  Migrations    |        Version:  2.0
               Severity:  Normal        |       Keywords:
           Triage Stage:  Unreviewed    |      Has patch:  0
    Needs documentation:  0             |    Needs tests:  0
Patch needs improvement:  0             |  Easy pickings:  0
                  UI/UX:  0             |
----------------------------------------+------------------------
 As the title says Django doesn't check the type of one-off value. Recently
 I had a field like this

 {{{
     start_time = models.DateTimeField(editable=False)
 }}}

 1) I gave to the field an one-off value
 {{{
 >>> 0
 }}}

 2) then the migration file had those operations

 {{{
     operations = [
         migrations.AddField(
             model_name='x',
             name='outcome',
             field=models.CharField(default='TO', max_length=16),
             preserve_default=False,
         ),
         migrations.AddField(
             model_name='x',
             name='start_time',
             field=models.DateTimeField(default=0 editable=False),
             preserve_default=False,
         ),
     ]
 }}}

 when I found my error i couldn't really do anything
 I changed
 {{{
             field=models.DateTimeField(default=0, editable=False),
 }}}
 to
 {{{
             field=models.DateTimeField(default=timezone.now,
 editable=False),
 }}}

 so after updating my migration file, I got an error
 "django.db.utils.OperationalError: (1060, "Duplicate column name
 "outcome")".
 I could neither re-migrate because the operations isn't a bunch of queries
 in transaction, nor create a new migration.
 Only reverting to zero and apply all migrations again worked.

 This has to have a workaround.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/28980>
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/049.2d3a35e4f892f4d65f07dd06c90cfeff%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to