Commit d3cf6cfa authored by Vajrasky Kok's avatar Vajrasky Kok Committed by Tim Graham
Browse files

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.
parent b22d6c47
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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
+1 −1
Original line number Diff line number Diff line
@@ -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
+6 −0
Original line number Diff line number Diff line
@@ -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
+2 −3
Original line number Diff line number Diff line
@@ -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)
+1 −2
Original line number Diff line number Diff line
@@ -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):
Loading