Django model default -


i add "default=othermodel.get_first()" model, , did "python manage.py makemigrations", , i'm getting following error. how can around this?

 file "/opt/titan/local/lib/python2.7/site-packages/django/db/migrations/writer.py", line 464, in serialize     "topics/migrations/#migration-serializing" % (value, get_docs_version()) valueerror: cannot serialize: <conventiontypes: hy - half year> there values django cannot serialize migration files. more, see https://docs.djangoproject.com/en/1.8/topics/migrations/#migration-serializing   class mymodel(models.model):     field = models.foreignkey(othermodel, blank=false, null=false, default=othermodel.get_first())  

try this:

def get_default():     return othermodel.get_first()  class mymodel(models.model):     field = models.foreignkey(othermodel, blank=false, null=false, default=get_default)  

you can hardcode pk it's ugly.


Comments