diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py
index c1ef625..bacd998 100644
a
|
b
|
class DatabaseOperations(BaseDatabaseOperations):
|
261 | 261 | sql.append('%s %s;' % (style.SQL_KEYWORD('TRUNCATE'), style.SQL_FIELD(self.quote_name(table)))) |
262 | 262 | sql.append('SET FOREIGN_KEY_CHECKS = 1;') |
263 | 263 | |
264 | | # 'ALTER TABLE table AUTO_INCREMENT = 1;'... style SQL statements |
265 | | # to reset sequence indices |
266 | | sql.extend(["%s %s %s %s %s;" % \ |
267 | | (style.SQL_KEYWORD('ALTER'), |
268 | | style.SQL_KEYWORD('TABLE'), |
269 | | style.SQL_TABLE(self.quote_name(sequence['table'])), |
270 | | style.SQL_KEYWORD('AUTO_INCREMENT'), |
271 | | style.SQL_FIELD('= 1'), |
272 | | ) for sequence in sequences]) |
| 264 | # Truncate already resets the AUTO_INCREMENT field from |
| 265 | # MySQL version 5.0.13 onwards. Refs #16961. |
| 266 | if self.connection.mysql_version < (5,0,13): |
| 267 | sql.extend( |
| 268 | ["%s %s %s %s %s;" % \ |
| 269 | (style.SQL_KEYWORD('ALTER'), |
| 270 | style.SQL_KEYWORD('TABLE'), |
| 271 | style.SQL_TABLE(self.quote_name(sequence['table'])), |
| 272 | style.SQL_KEYWORD('AUTO_INCREMENT'), |
| 273 | style.SQL_FIELD('= 1'), |
| 274 | ) for sequence in sequences]) |
273 | 275 | return sql |
274 | 276 | else: |
275 | 277 | return [] |
diff --git a/tests/regressiontests/backends/tests.py b/tests/regressiontests/backends/tests.py
index d5b1ea8..f87b9c4 100644
a
|
b
|
class OracleChecks(unittest.TestCase):
|
61 | 61 | def test_client_encoding(self): |
62 | 62 | # If the backend is Oracle, test that the client encoding is set |
63 | 63 | # correctly. This was broken under Cygwin prior to r14781. |
64 | | c = connection.cursor() # Ensure the connection is initialized. |
| 64 | connection.cursor() # Ensure the connection is initialized. |
65 | 65 | self.assertEqual(connection.connection.encoding, "UTF-8") |
66 | 66 | self.assertEqual(connection.connection.nencoding, "UTF-8") |
67 | 67 | |
| 68 | class MySQLTests(TestCase): |
| 69 | @unittest.skipUnless(connection.vendor == 'mysql', |
| 70 | "Test valid only for MySQL") |
| 71 | def test_autoincrement(self): |
| 72 | """ |
| 73 | Check that auto_increment fields are reset correctly by sql_flush(). |
| 74 | Before MySQL version 5.0.13 TRUNCATE did not do auto_increment reset. |
| 75 | Refs #16961. |
| 76 | """ |
| 77 | statements = connection.ops.sql_flush(no_style(), |
| 78 | tables=['test'], |
| 79 | sequences=[{ |
| 80 | 'table': 'test', |
| 81 | 'col': 'somecol', |
| 82 | }]) |
| 83 | found_reset = False |
| 84 | for sql in statements: |
| 85 | found_reset = found_reset or 'ALTER TABLE' in sql |
| 86 | if connection.mysql_version < (5,0,13): |
| 87 | self.assertTrue(found_reset) |
| 88 | else: |
| 89 | self.assertFalse(found_reset) |
| 90 | |
| 91 | |
68 | 92 | class DateQuotingTest(TestCase): |
69 | 93 | |
70 | 94 | def test_django_date_trunc(self): |
diff --git a/tests/regressiontests/test_runner/models.py b/tests/regressiontests/test_runner/models.py
index e69de29..9a072e6 100644
a
|
b
|
|
| 1 | from django.db import models |
| 2 | |
| 3 | class Person(models.Model): |
| 4 | first_name = models.CharField(max_length=20) |
| 5 | last_name = models.CharField(max_length=20) |
diff --git a/tests/regressiontests/test_runner/tests.py b/tests/regressiontests/test_runner/tests.py
index ccb65b4..3fc8d7f 100644
a
|
b
|
from optparse import make_option
|
8 | 8 | from django.core.exceptions import ImproperlyConfigured |
9 | 9 | from django.core.management import call_command |
10 | 10 | from django import db |
11 | | from django.test import simple |
| 11 | from django.db import connection |
| 12 | from django.test import simple, TransactionTestCase |
12 | 13 | from django.test.simple import DjangoTestSuiteRunner, get_tests |
13 | 14 | from django.test.testcases import connections_support_transactions |
14 | 15 | from django.utils import unittest |
15 | 16 | from django.utils.importlib import import_module |
16 | 17 | |
17 | 18 | from ..admin_scripts.tests import AdminScriptTestCase |
| 19 | from .models import Person |
18 | 20 | |
19 | 21 | |
20 | 22 | TEST_APP_OK = 'regressiontests.test_runner.valid_app.models' |
… |
… |
class Sqlite3InMemoryTestDbs(unittest.TestCase):
|
262 | 264 | self.assertTrue(connections_support_transactions(), msg) |
263 | 265 | finally: |
264 | 266 | db.connections = old_db_connections |
| 267 | |
| 268 | |
| 269 | class AutoIncrementResetTest(TransactionTestCase): |
| 270 | """ |
| 271 | Here we test creating the same model two times in different test methods, |
| 272 | and check that both times they get "1" as their PK value. That is, we test |
| 273 | that AutoField values start from 1 for each transactional test case. |
| 274 | """ |
| 275 | @unittest.skipIf(connection.vendor == 'oracle', |
| 276 | "Oracle's auto-increment fields are not reset between " |
| 277 | "tests") |
| 278 | def test_autoincrement_reset1(self): |
| 279 | p = Person.objects.create(first_name='Jack', last_name='Smith') |
| 280 | self.assertEquals(p.pk, 1) |
| 281 | |
| 282 | @unittest.skipIf(connection.vendor == 'oracle', |
| 283 | "Oracle's auto-increment fields are not reset between " |
| 284 | "tests") |
| 285 | def test_autoincrement_reset2(self): |
| 286 | p = Person.objects.create(first_name='Jack', last_name='Smith') |
| 287 | self.assertEquals(p.pk, 1) |