Answer the question
In order to leave comments, you need to log in
Django - error while doing makemigrations?
Hello.
There is a problem with one field in the model.
class UserProfile(models.Model):
user = models.OneToOneField(User)
activation_key = models.CharField(max_length=40, blank=True)
key_expires = models.DateTimeField(default=datetime.date.today())
def __unicode__(self):
return self.user.username
class Meta:
verbose_name_plural=u'User profiles'
Answer the question
In order to leave comments, you need to log in
1) In default you stuff the RESULT of the function, not the function itself. That. the default value for all key_expires fields will be exactly when you last made makemigrations. By the way, you can do makemigrations endlessly, there will always be something new :)
2) You are trying to assign a date to the Date Time field. There is a DateField for this.
3) There are two huge differences between:
import datetime
datetime.date.today()
from datetime import datetime
datetime.date.today()
key_expires = models.DateField(auto_now_add=True)
You pass to default= not a callable function, but its computed value at the time the program starts. The problem is that key_expires will default to the server start date. On the next day of work, this will be yesterday's date :)
if you write like this:
key_expires = models.DateTimeField(default=datetime.date.today)
those. without brackets, the application will work correctly. And migrations will be created as a nice bonus.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question