mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #17653 -- Changed MySQL backend to raise a ValueError if zero is used as an AutoField value.
Thanks to Sylvain Lebon for the report, krzysiumed for the patch and charettes and claudep for reviews. git-svn-id: http://code.djangoproject.com/svn/django/trunk@17933 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -13,7 +13,8 @@ from django.db import (backend, connection, connections, DEFAULT_DB_ALIAS,
|
||||
from django.db.backends.signals import connection_created
|
||||
from django.db.backends.postgresql_psycopg2 import version as pg_version
|
||||
from django.db.utils import ConnectionHandler, DatabaseError, load_backend
|
||||
from django.test import TestCase, skipUnlessDBFeature, TransactionTestCase
|
||||
from django.test import (TestCase, skipUnlessDBFeature, skipIfDBFeature,
|
||||
TransactionTestCase)
|
||||
from django.test.utils import override_settings
|
||||
from django.utils import unittest
|
||||
|
||||
@@ -642,3 +643,15 @@ class BackendLoadingTests(TestCase):
|
||||
self.assertRaisesRegexp(ImproperlyConfigured,
|
||||
"Try using django.db.backends.sqlite3 instead",
|
||||
load_backend, 'sqlite3')
|
||||
|
||||
|
||||
class MySQLPKZeroTests(TestCase):
|
||||
"""
|
||||
Zero as id for AutoField should raise exception in MySQL, because MySQL
|
||||
does not allow zero for automatic primary key.
|
||||
"""
|
||||
|
||||
@skipIfDBFeature('allows_primary_key_0')
|
||||
def test_zero_as_autoval(self):
|
||||
with self.assertRaises(ValueError):
|
||||
models.Square.objects.create(id=0, root=0, square=1)
|
||||
|
||||
Reference in New Issue
Block a user