mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Used CommandError in createcachetable command.
Raising CommandError whenever a management command meets an error condition is the standard way to handle errors in commands.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from optparse import make_option
|
||||
|
||||
from django.core.cache.backends.db import BaseDatabaseCache
|
||||
from django.core.management.base import LabelCommand
|
||||
from django.core.management.base import LabelCommand, CommandError
|
||||
from django.db import connections, router, transaction, models, DEFAULT_DB_ALIAS
|
||||
from django.db.utils import DatabaseError
|
||||
|
||||
@@ -55,11 +55,10 @@ class Command(LabelCommand):
|
||||
try:
|
||||
curs.execute("\n".join(full_statement))
|
||||
except DatabaseError as e:
|
||||
self.stderr.write(
|
||||
transaction.rollback_unless_managed(using=db)
|
||||
raise CommandError(
|
||||
"Cache table '%s' could not be created.\nThe error was: %s." %
|
||||
(tablename, e))
|
||||
transaction.rollback_unless_managed(using=db)
|
||||
else:
|
||||
for statement in index_output:
|
||||
curs.execute(statement)
|
||||
transaction.commit_unless_managed(using=db)
|
||||
for statement in index_output:
|
||||
curs.execute(statement)
|
||||
transaction.commit_unless_managed(using=db)
|
||||
|
||||
Reference in New Issue
Block a user