diff --git a/django/core/management/commands/createcachetable.py b/django/core/management/commands/createcachetable.py
index 287a036..a92ccaa 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 | except DatabaseError, e: |
| 58 | self.stderr.write( |
| 59 | self.style.ERROR("Cache database '%s' could not be created.\nThe error was: %s.\n" % |
| 60 | (tablename, e))) |
| 61 | transaction.rollback_unless_managed(using=db) |
| 62 | else: |
| 63 | for statement in index_output: |
| 64 | curs.execute(statement) |
| 65 | transaction.commit_unless_managed(using=db) |
diff --git a/tests/regressiontests/cache/tests.py b/tests/regressiontests/cache/tests.py
index d31a5e0..c368a51 100644
a
|
b
|
class DBCacheTests(BaseCacheTests, TransactionTestCase):
|
817 | 817 | self.cache = get_cache('db://%s?max_entries=30&cull_frequency=0' % self._table_name) |
818 | 818 | self.perform_cull_test(50, 18) |
819 | 819 | |
| 820 | def test_second_call_dont_crash(self): |
| 821 | from StringIO import StringIO |
| 822 | out = StringIO() |
| 823 | management.call_command('createcachetable', self._table_name, verbosity=0, interactive=False, stderr=out) |
| 824 | self.assertTrue("Cache database 'test cache table' could not be created" in out.getvalue()) |
| 825 | |
820 | 826 | |
821 | 827 | DBCacheWithTimeZoneTests = override_settings(USE_TZ=True)(DBCacheTests) |
822 | 828 | |