#22363: namespace issues with date when used as default value
----------------------------+------------------------
     Reporter:  linovia     |      Owner:  linovia
         Type:  Bug         |     Status:  new
    Component:  Migrations  |    Version:  1.7-beta-1
     Severity:  Normal      |   Keywords:
 Triage Stage:  Unreviewed  |  Has patch:  1
Easy pickings:  0           |      UI/UX:  0
----------------------------+------------------------
 While playing with Django 1.7 I noticed there was an issue with some
 generated migrations.

 I had a model to which I added:

 {{{
 some_date = models.DateField()
 }}}

 I ran the makemigration and it prompted me to enter a default value:
 {{{
 $ python manage.py makemigrations
 You are trying to add a non-nullable field 'some_date' to post without a
 default;
 we can't do that (the database needs something to populate existing rows).
 Please select a fix:
  1) Provide a one-off default now (will be set on all existing rows)
  2) Quit, and let me add a default in models.py
 Select an option: 1
 Please enter the default value now, as valid Python
 The datetime module is available, so you can do e.g. datetime.date.today()
 >>> datetime.date.today()
 Migrations for 'blog':
   0006_post_some_date.py:
     - Add field some_date to post
 }}}

 It created the following migration:

 {{{
 # encoding: utf8
 from django.db import models, migrations
 import datetime


 class Migration(migrations.Migration):

     dependencies = [
         ('blog', '0005_post_image_big'),
     ]

     operations = [
         migrations.AddField(
             model_name='post',
             name='some_date',
             field=models.DateField(default=date(2014, 3, 31)),
             preserve_default=False,
         ),
     ]
 }}}

 Now if you look at the default, it uses date(...) while it only imports
 datetime and thus will not be able to run.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/22363>
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/050.dbcc3642d9080d40b0a5819bff3ac6b7%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to