ValueError: Cannot add *: instance is on database “default”, value is on database “None”

后端 未结 1 988
渐次进展
渐次进展 2021-02-02 07:20
In [1]: from editor.models import *
In [4]: from subscriptions.models import *
In [5]: template = StockTemplate.objects.create(name=\'Template 1\')
In [6]: template
Out[         


        
相关标签:
1条回答
  • 2021-02-02 07:46

    The problem here is you need call the method save for both objects before add:

    template.save()
    plan.save()
    plan.templates.add(template)
    

    Django can not add a template of a plan if none of that objects don't have an id

    0 讨论(0)
提交回复
热议问题