[Django]-FieldError at /admin/ – Unknown field(s) (added_on) specified for UserProfile

45👍

Your problem is the auto_now_add=True on that field. See the notes on the documentation for DateField:

Note that the current date is always used; it’s not just a default value that you can override.

and

As currently implemented, setting auto_now or auto_now_add to True will cause the field to have editable=False and blank=True set.

Since editable=False, you can’t include it in the list of fields for that form (you could put it in readonly_fields, of course).

If you want the value to take the creation date as a default, but still allow it to be edited and overridden, you should use default instead:

added_on = models.DateTimeField(default=datetime.datetime.now)

(side note, you should always use the callable for the default value, without the calling parentheses).

Leave a comment