[Answer]-Type Error : 'authors' is an invalid key argument for this function

1👍

You can’t assign ManyToMany field in the model’s constructor. Moreover you can’t set the M2M field to unsaved instance. So you have to save the instance first and then assign the M2M field:

mybook = Author.objects.create(title="The Prince", publisher=mas,
                               publication_date=date(1989, 6, 30))
mybook.authors.add(mak) # or mybook.authors = [mak]

Leave a comment