[Answered ]-In django, why get_or_create doesn't work if the items contain ForeignKey

2👍

You need to instantiate/get_or_create Keyword first:

keyword, _ = Keyword.objects.get_or_create(name='keyword_name')
case, flag = Case.objects.get_or_create(name='case_name', keywords=keyword)

Hope that works for you.

👤alecxe

Leave a comment