1👍
✅
This error is saying that you are trying to access a Many2Many
relation before saving your object in the database (i.e. without ID/PK). Unfortunately you can’t access this Many2Many
relation from your field in clean method when you didn’t save your object in the database. Because these kind of objects (Many2Many
) will be added to your instance after you create your objects. Since Django needs to query your through model based on your current instance, and when there isn’t any instance it can not make a query for it and that is the main reason why it is raising error.
Basically you can not have access to objects’ Many2Many
relation (without ID/PK or before saving your new instance) in model’s layer validators.
Source:stackexchange.com