There are many questions about this Exception:
AttributeError: Cannot set values on a ManyToManyField which specifies
an intermediary model.
Use myapp.MyThroughModel's Manager instead.
The docs
You can’t just create a relationship between a Person and a Group - you need to specify all the detail for the relationship required by the Membership model. The simple add, create and assignment calls don’t provide a way to specify this extra detail. As a result, they are disabled for many-to-many relationships that use an intermediate model.
But all my attributes/columns of MyThroughModel are optional. The manager could create them.
How can I write a custom manager to automatically create MyThroughModel instances?
I need a solution at ORM-level, not Form-level.
I found a way to tell django to ignore the extra data:
class MyThroughModel(Model):
class Meta():
auto_created=True
...
Update
This creates issues with the django internal migrations. We updated our code and don't use auto_created = True
any more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With