summaryrefslogtreecommitdiff
path: root/django/core/management/commands/flush.py
diff options
context:
space:
mode:
Diffstat (limited to 'django/core/management/commands/flush.py')
-rw-r--r--django/core/management/commands/flush.py79
1 files changed, 37 insertions, 42 deletions
diff --git a/django/core/management/commands/flush.py b/django/core/management/commands/flush.py
index c94072fd02..6836fe35ca 100644
--- a/django/core/management/commands/flush.py
+++ b/django/core/management/commands/flush.py
@@ -21,62 +21,57 @@ class Command(NoArgsCommand):
help = "Executes ``sqlflush`` on the current database."
def handle_noargs(self, **options):
- if not options['database']:
- dbs = connections
- else:
- dbs = [options['database']]
-
+ db = options.get('database', DEFAULT_DB_ALIAS)
+ connection = connections[db]
verbosity = int(options.get('verbosity', 1))
interactive = options.get('interactive')
self.style = no_style()
+ # Import the 'management' module within each installed app, to register
+ # dispatcher events.
for app_name in settings.INSTALLED_APPS:
try:
import_module('.management', app_name)
except ImportError:
pass
- for db in dbs:
- connection = connections[db]
- # Import the 'management' module within each installed app, to register
- # dispatcher events.
- sql_list = sql_flush(self.style, connection, only_django=True)
+ sql_list = sql_flush(self.style, connection, only_django=True)
- if interactive:
- confirm = raw_input("""You have requested a flush of the database.
- This will IRREVERSIBLY DESTROY all data currently in the %r database,
- and return each table to the state it was in after syncdb.
- Are you sure you want to do this?
+ if interactive:
+ confirm = raw_input("""You have requested a flush of the database.
+This will IRREVERSIBLY DESTROY all data currently in the %r database,
+and return each table to the state it was in after syncdb.
+Are you sure you want to do this?
- Type 'yes' to continue, or 'no' to cancel: """ % connection.settings_dict['NAME'])
- else:
- confirm = 'yes'
+ Type 'yes' to continue, or 'no' to cancel: """ % connection.settings_dict['NAME'])
+ else:
+ confirm = 'yes'
- if confirm == 'yes':
- try:
- cursor = connection.cursor()
- for sql in sql_list:
- cursor.execute(sql)
- except Exception, e:
- transaction.rollback_unless_managed(using=db)
- raise CommandError("""Database %s couldn't be flushed. Possible reasons:
- * The database isn't running or isn't configured correctly.
- * At least one of the expected database tables doesn't exist.
- * The SQL was invalid.
- Hint: Look at the output of 'django-admin.py sqlflush'. That's the SQL this command wasn't able to run.
- The full error: %s""" % (connection.settings_dict['NAME'], e))
- transaction.commit_unless_managed(using=db)
+ if confirm == 'yes':
+ try:
+ cursor = connection.cursor()
+ for sql in sql_list:
+ cursor.execute(sql)
+ except Exception, e:
+ transaction.rollback_unless_managed(using=db)
+ raise CommandError("""Database %s couldn't be flushed. Possible reasons:
+ * The database isn't running or isn't configured correctly.
+ * At least one of the expected database tables doesn't exist.
+ * The SQL was invalid.
+Hint: Look at the output of 'django-admin.py sqlflush'. That's the SQL this command wasn't able to run.
+The full error: %s""" % (connection.settings_dict['NAME'], e))
+ transaction.commit_unless_managed(using=db)
- # Emit the post sync signal. This allows individual
- # applications to respond as if the database had been
- # sync'd from scratch.
- emit_post_sync_signal(models.get_models(), verbosity, interactive, db)
+ # Emit the post sync signal. This allows individual
+ # applications to respond as if the database had been
+ # sync'd from scratch.
+ emit_post_sync_signal(models.get_models(), verbosity, interactive, db)
- # Reinstall the initial_data fixture.
- kwargs = options.copy()
- kwargs['database'] = db
- call_command('loaddata', 'initial_data', **kwargs)
+ # Reinstall the initial_data fixture.
+ kwargs = options.copy()
+ kwargs['database'] = db
+ call_command('loaddata', 'initial_data', **kwargs)
- else:
- print "Flush cancelled."
+ else:
+ print "Flush cancelled."