summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--django/db/models/sql/subqueries.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/django/db/models/sql/subqueries.py b/django/db/models/sql/subqueries.py
index b293ff8925..f421643dc8 100644
--- a/django/db/models/sql/subqueries.py
+++ b/django/db/models/sql/subqueries.py
@@ -313,9 +313,12 @@ class InsertQuery(Query):
def execute_sql(self, return_id=False):
cursor = super(InsertQuery, self).execute_sql(None)
- if return_id and cursor:
- return self.connection.ops.last_insert_id(cursor,
- self.model._meta.db_table, self.model._meta.pk.column)
+ if not (return_id and cursor):
+ return
+ if self.connection.features.can_return_id_from_insert:
+ return cursor.fetchone()[0]
+ return self.connection.ops.last_insert_id(cursor,
+ self.model._meta.db_table, self.model._meta.pk.column)
def insert_values(self, insert_values, raw_values=False):
"""