Using Django 1.7, whenever I perform a makemigrations, I get a change on one of my models:
(venv) >> python manage.py makemigrations myapp
Migrations for 'myapp':
0005_auto_20141206_1129.py:
- Alter field date on observation
This is due to my Observation class using datetime.today():
class Observation(model.Models):
date = models.DateField(default=datetime.datetime.today())
Is there an easy way to avoid creating migration files for this, but at the same time keeping the default of today() whenever an Observation is created?
The problem is that each time this code is run the default changes to the current value of today(). That's because you're actually calling the function instead of passing it as a callable. Simply leave off the trailing () and you should be fine.
(Note that you should use datetime.date.today, since you want a date value, not a datetime value.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With