mirror of
https://github.com/django/django.git
synced 2025-10-28 08:06:09 +00:00
Fixed #34586 -- Made QuerySet.create() raise ValueError for reverse one-to-many relations.
This commit is contained in:
committed by
Mariusz Felisiak
parent
aa3cb3f372
commit
e02fc58889
@@ -662,6 +662,15 @@ class QuerySet(AltersData):
|
||||
Create a new object with the given kwargs, saving it to the database
|
||||
and returning the created object.
|
||||
"""
|
||||
reverse_one_to_one_fields = frozenset(kwargs).intersection(
|
||||
self.model._meta._reverse_one_to_one_field_names
|
||||
)
|
||||
if reverse_one_to_one_fields:
|
||||
raise ValueError(
|
||||
"The following fields do not exist in this model: %s"
|
||||
% ", ".join(reverse_one_to_one_fields)
|
||||
)
|
||||
|
||||
obj = self.model(**kwargs)
|
||||
self._for_write = True
|
||||
obj.save(force_insert=True, using=self.db)
|
||||
|
||||
Reference in New Issue
Block a user