summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVajrasky Kok <sky.kok@speaklikeaking.com>2013-11-24 21:12:22 +0800
committerTim Graham <timograham@gmail.com>2014-02-06 05:16:40 -0500
commitd3cf6cfacfb828faad4f4f97c904e259304649b3 (patch)
treeae44bc63cc45a144edbec26bb5590b8225e70233
parentb22d6c47a7e4c7ab26a8b7b033d11fa6743aae86 (diff)
Fixed #17713 -- Renamed BaseDatabaseFeatures.allows_primary_key_0 to allows_auto_pk_0.
MySQL does allow primary key with value 0. It only forbids autoincrement primary key with value 0. Thanks Claude Paroz for the report.
-rw-r--r--django/db/backends/__init__.py4
-rw-r--r--django/db/backends/mysql/base.py2
-rw-r--r--docs/releases/1.7.txt6
-rw-r--r--tests/backends/tests.py5
-rw-r--r--tests/bulk_create/tests.py3
-rw-r--r--tests/inline_formsets/tests.py2
-rw-r--r--tests/serializers_regress/tests.py6
7 files changed, 16 insertions, 12 deletions
diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py
index 50b8745f47..59db3220fd 100644
--- a/django/db/backends/__init__.py
+++ b/django/db/backends/__init__.py
@@ -613,8 +613,8 @@ class BaseDatabaseFeatures(object):
# Is there a 1000 item limit on query parameters?
supports_1000_query_parameters = True
- # Can an object have a primary key of 0? MySQL says No.
- allows_primary_key_0 = True
+ # Can an object have an autoincrement primary key of 0? MySQL says No.
+ allows_auto_pk_0 = True
# Do we need to NULL a ForeignKey out, or can the constraint check be
# deferred
diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py
index b752f4738f..d35d7a3888 100644
--- a/django/db/backends/mysql/base.py
+++ b/django/db/backends/mysql/base.py
@@ -177,7 +177,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
supports_date_lookup_using_string = False
supports_timezones = False
requires_explicit_null_ordering_when_grouping = True
- allows_primary_key_0 = False
+ allows_auto_pk_0 = False
uses_savepoints = True
atomic_transactions = False
supports_check_constraints = False
diff --git a/docs/releases/1.7.txt b/docs/releases/1.7.txt
index e802f257ae..a51c3dc981 100644
--- a/docs/releases/1.7.txt
+++ b/docs/releases/1.7.txt
@@ -1010,6 +1010,12 @@ Miscellaneous
to ``False``). If you maintain a custom database backend, you should check
that method.
+* The ``django.db.backends.BaseDatabaseFeatures.allows_primary_key_0``
+ attribute has been renamed to ``allows_auto_pk_0`` to better describe it.
+ It's ``True`` for all database backends included with Django except MySQL
+ which does allow primary keys with value 0. It only forbids *autoincrement*
+ primary keys with value 0.
+
.. _deprecated-features-1.7:
Features deprecated in 1.7
diff --git a/tests/backends/tests.py b/tests/backends/tests.py
index 9548f60a77..d5116898ec 100644
--- a/tests/backends/tests.py
+++ b/tests/backends/tests.py
@@ -934,10 +934,9 @@ class ThreadTests(TestCase):
class MySQLPKZeroTests(TestCase):
"""
Zero as id for AutoField should raise exception in MySQL, because MySQL
- does not allow zero for automatic primary key.
+ does not allow zero for autoincrement primary key.
"""
-
- @skipIfDBFeature('allows_primary_key_0')
+ @skipIfDBFeature('allows_auto_pk_0')
def test_zero_as_autoval(self):
with self.assertRaises(ValueError):
models.Square.objects.create(id=0, root=0, square=1)
diff --git a/tests/bulk_create/tests.py b/tests/bulk_create/tests.py
index 367cbde04d..8648184223 100644
--- a/tests/bulk_create/tests.py
+++ b/tests/bulk_create/tests.py
@@ -70,13 +70,12 @@ class BulkCreateTests(TestCase):
"CA", "IL", "ME", "NY",
], attrgetter("two_letter_code"))
- @skipIfDBFeature('allows_primary_key_0')
+ @skipIfDBFeature('allows_auto_pk_0')
def test_zero_as_autoval(self):
"""
Zero as id for AutoField should raise exception in MySQL, because MySQL
does not allow zero for automatic primary key.
"""
-
valid_country = Country(name='Germany', iso_two_letter='DE')
invalid_country = Country(id=0, name='Poland', iso_two_letter='PL')
with self.assertRaises(ValueError):
diff --git a/tests/inline_formsets/tests.py b/tests/inline_formsets/tests.py
index 87add7f6e6..6f6bc76ac8 100644
--- a/tests/inline_formsets/tests.py
+++ b/tests/inline_formsets/tests.py
@@ -162,7 +162,7 @@ class InlineFormsetFactoryTest(TestCase):
Parent, Child, exclude=('school',), fk_name='mother'
)
- @skipUnlessDBFeature('allows_primary_key_0')
+ @skipUnlessDBFeature('allows_auto_pk_0')
def test_zero_primary_key(self):
# Regression test for #21472
poet = Poet.objects.create(id=0, name='test')
diff --git a/tests/serializers_regress/tests.py b/tests/serializers_regress/tests.py
index d71dd8c406..489e68ce77 100644
--- a/tests/serializers_regress/tests.py
+++ b/tests/serializers_regress/tests.py
@@ -389,10 +389,10 @@ if connection.features.interprets_empty_strings_as_nulls:
data[2]._meta.get_field('data').empty_strings_allowed and
data[3] is None)]
-# Regression test for #8651 -- a FK to an object iwth PK of 0
+# Regression test for #8651 -- a FK to an object with PK of 0
# This won't work on MySQL since it won't let you create an object
-# with a primary key of 0,
-if connection.features.allows_primary_key_0:
+# with an autoincrement primary key of 0,
+if connection.features.allows_auto_pk_0:
test_data.extend([
(data_obj, 0, Anchor, "Anchor 0"),
(fk_obj, 465, FKData, 0),