#35037: DateTimeField with auto_now_add and default is inconsistent/broken
-------------------------------------+-------------------------------------
               Reporter:  Norbert    |          Owner:  nobody
  Preining                           |
                   Type:  Bug        |         Status:  new
              Component:  Core       |        Version:  5.0
  (Management commands)              |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 I wanted to update a model by adding a field
 {{{
 created_at = models.DateTimeField(auto_now_add=True)
 }}}


 But when I wanted to create migrations I got:
 {{{
 $ python manage.py makemigrations users
 It is impossible to add the field 'created_at' with 'auto_now_add=True' to
 customuser without providing a default. This is because the database needs
 something to populate existing rows.
  1) Provide a one-off default now which will be set on all existing rows
  2) Quit and manually define a default value in models.py.
 Select an option: 2
 }}}

 Ok, according to this, I added a default as in
 {{{
 created_at = models.DateTimeField(auto_now_add=True, default=datetime.now)
 }}}

 but creating migrations still complain:
 {{{
 $ python manage.py makemigrations users
 SystemCheckError: System check identified some issues:

 ERRORS:
 users.CustomUser.created_at: (fields.E160) The options auto_now,
 auto_now_add, and default are mutually exclusive. Only one of these
 options may be present.
 }}}

 That means, according to the message from manage.py:
 - `auto_now`, `auto_now_add`, and `default` are mutually exclusive
 - but at the same time, I need to add a default for `auto_now_add` to be
 added

 I am puzzled

-- 
Ticket URL: <https://code.djangoproject.com/ticket/35037>
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018c6880444d-4ded9f97-3d4b-482a-8d4d-a9f2b9b76050-000000%40eu-central-1.amazonses.com.

Reply via email to