8👍
You misunderstand what auto_now
does
Automatically set the field to now every time the object is saved.
You’ll still need to specify a valid default or allow for null values with null=True
2👍
You cannot assign None
to updated_datetime
because you have not set null=True
in the model.
You have created a migration that tells django what to do if it encounters existing rows in the circuit
table when adding the field but that is not the same as being able to do it.
The default value asked for by the migration does not check that value is allowed to be used, it’s trusting you to know what you are doing.
In your migration use datetime.now()
rather than None
.
- [Django]-Open() "/root/project/static/*.css" failed (13: Permission denied) nginx
- [Django]-How to use date__range filter efficiently in django
- [Django]-Pass variable from middleware to templates
- [Django]-Django-compressor: disable caching using precompilers
- [Django]-Server lagging – Django + mongodb + cronjob
1👍
DateField.auto_now
Automatically set the field to now every time the object is saved.
DateField.auto_now_add
Automatically set the field to now when the object is first created.
You can use anyone:
created_date = models.DateTimeField(auto_now_add=True, null=True)
or
created_date = models.DateTimeField(null=True)
or
from django.utils import timezone
created_date = models.DateTimeField(default=timezone.now)
- [Django]-Get a dropdown of states in Django Admin
- [Django]-Django 1.3 internationalization… switching language requires server restart?
0👍
-
You have to delete all migrations and erase your database data too and do migrations again
-
excute commands:
python manage.py makemigrations
python manage.py migrate --fake