summaryrefslogtreecommitdiff
path: root/django/db/backends/mysql/operations.py
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2020-07-20 09:48:31 +0200
committerGitHub <noreply@github.com>2020-07-20 09:48:31 +0200
commit83f55aafdd635189c010cff403f66b54d695921a (patch)
treeba3f3244e4300bc055555f7693363f28fa885169 /django/db/backends/mysql/operations.py
parent730711e8282893723f993f55d3e3b0c823cfdb9a (diff)
downloaddjango-83f55aafdd635189c010cff403f66b54d695921a.tar.gz
Fixed #17653 -- Allowed using zero as AutoFields value on MySQL if NO_AUTO_VALUE_ON_ZERO SQL mode is enabled.
Diffstat (limited to 'django/db/backends/mysql/operations.py')
-rw-r--r--django/db/backends/mysql/operations.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/django/db/backends/mysql/operations.py b/django/db/backends/mysql/operations.py
index ffddb64e3c..05523fcdbe 100644
--- a/django/db/backends/mysql/operations.py
+++ b/django/db/backends/mysql/operations.py
@@ -227,8 +227,9 @@ class DatabaseOperations(BaseDatabaseOperations):
]
def validate_autopk_value(self, value):
- # MySQLism: zero in AUTO_INCREMENT field does not work. Refs #17653.
- if value == 0:
+ # Zero in AUTO_INCREMENT field does not work without the
+ # NO_AUTO_VALUE_ON_ZERO SQL mode.
+ if value == 0 and not self.connection.features.allows_auto_pk_0:
raise ValueError('The database backend does not accept 0 as a '
'value for AutoField.')
return value
@@ -266,6 +267,9 @@ class DatabaseOperations(BaseDatabaseOperations):
def max_name_length(self):
return 64
+ def pk_default_value(self):
+ return 'NULL'
+
def bulk_insert_sql(self, fields, placeholder_rows):
placeholder_rows_sql = (", ".join(row) for row in placeholder_rows)
values_sql = ", ".join("(%s)" % sql for sql in placeholder_rows_sql)