diff --git a/django/core/management/commands/createcachetable.py b/django/core/management/commands/createcachetable.py
index 287a036..47dabf7 100644
a
|
b
|
from optparse import make_option
|
3 | 3 | from django.core.cache.backends.db import BaseDatabaseCache |
4 | 4 | from django.core.management.base import LabelCommand |
5 | 5 | from django.db import connections, router, transaction, models, DEFAULT_DB_ALIAS |
| 6 | from django.db.utils import DatabaseError |
6 | 7 | |
7 | 8 | class Command(LabelCommand): |
8 | 9 | help = "Creates the table needed to use the SQL cache backend." |
… |
… |
class Command(LabelCommand):
|
51 | 52 | full_statement.append(' %s%s' % (line, i < len(table_output)-1 and ',' or '')) |
52 | 53 | full_statement.append(');') |
53 | 54 | curs = connection.cursor() |
54 | | curs.execute("\n".join(full_statement)) |
55 | | for statement in index_output: |
56 | | curs.execute(statement) |
57 | | transaction.commit_unless_managed(using=db) |
| 55 | try: |
| 56 | curs.execute("\n".join(full_statement)) |
| 57 | for statement in index_output: |
| 58 | curs.execute(statement) |
| 59 | transaction.commit_unless_managed(using=db) |
| 60 | except DatabaseError, e: |
| 61 | self.stderr.write( |
| 62 | self.style.ERROR("Cache database '%s' could not be created.\nThe error was: %s.\n" % |
| 63 | (tablename, e))) |
| 64 | transaction.rollback_unless_managed(using=db) |
diff --git a/tests/regressiontests/cache/tests.py b/tests/regressiontests/cache/tests.py
index c5dc457..eabbfac 100644
a
|
b
|
class DBCacheTests(BaseCacheTests, TransactionTestCase):
|
776 | 776 | self.cache = get_cache('db://%s?max_entries=30&cull_frequency=0' % self._table_name) |
777 | 777 | self.perform_cull_test(50, 18) |
778 | 778 | |
| 779 | def test_second_call_dont_crash(self): |
| 780 | from StringIO import StringIO |
| 781 | out = StringIO() |
| 782 | management.call_command('createcachetable', self._table_name, verbosity=0, interactive=False, stderr=out) |
| 783 | self.assertTrue("Cache database 'test cache table' could not be created" in out.getvalue()) |
| 784 | |
779 | 785 | |
780 | 786 | DBCacheWithTimeZoneTests = override_settings(USE_TZ=True)(DBCacheTests) |
781 | 787 | |