Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #15926 -- Added option --no-initial-data to syncdb and flush.

Thanks msiedlarek, jpaugh64 and vlinhart!
  • Loading branch information...
commit fedac99c859c626544d38fc0ea07207ef3fd101a 1 parent 4db34e7
@HonzaKral HonzaKral authored
View
7 django/core/management/commands/flush.py
@@ -16,6 +16,8 @@ class Command(NoArgsCommand):
make_option('--database', action='store', dest='database',
default=DEFAULT_DB_ALIAS, help='Nominates a database to flush. '
'Defaults to the "default" database.'),
+ make_option('--no-initial-data', action='store_false', dest='load_initial_data', default=True,
+ help='Tells Django not to load any initial data after database synchronization.'),
)
help = ('Returns the database to the state it was in immediately after '
'syncdb was executed. This means that all data will be removed '
@@ -79,7 +81,10 @@ def handle_noargs(self, **options):
# Reinstall the initial_data fixture.
kwargs = options.copy()
kwargs['database'] = db
- call_command('loaddata', 'initial_data', **kwargs)
+ if options.get('load_initial_data', True):
+ # Reinstall the initial_data fixture.
+ from django.core.management import call_command
+ call_command('loaddata', 'initial_data', **options)
else:
self.stdout.write("Flush cancelled.\n")
View
5 django/core/management/commands/syncdb.py
@@ -14,6 +14,8 @@ class Command(NoArgsCommand):
option_list = NoArgsCommand.option_list + (
make_option('--noinput', action='store_false', dest='interactive', default=True,
help='Tells Django to NOT prompt the user for input of any kind.'),
+ make_option('--no-initial-data', action='store_false', dest='load_initial_data', default=True,
+ help='Tells Django not to load any initial data after database synchronization.'),
make_option('--database', action='store', dest='database',
default=DEFAULT_DB_ALIAS, help='Nominates a database to synchronize. '
'Defaults to the "default" database.'),
@@ -25,9 +27,6 @@ def handle_noargs(self, **options):
verbosity = int(options.get('verbosity'))
interactive = options.get('interactive')
show_traceback = options.get('traceback')
-
- # Stealth option -- 'load_initial_data' is used by the testing setup
- # process to disable initial fixture loading.
load_initial_data = options.get('load_initial_data', True)
self.style = no_style()
View
15 docs/ref/django-admin.txt
@@ -245,6 +245,14 @@ prompts.
The :djadminopt:`--database` option may be used to specify the database
to flush.
+--no-initial-data
+~~~~~~~~~~~~~~~~~
+
+.. versionadded:: 1.5
+
+Use ``--no-initial-data`` to avoid loading the initial_data fixture.
+
+
inspectdb
---------
@@ -1024,6 +1032,13 @@ prompts.
The :djadminopt:`--database` option can be used to specify the database to
synchronize.
+--no-initial-data
+~~~~~~~~~~~~~~~~~
+
+.. versionadded:: 1.5
+
+Use ``--no-initial-data`` to avoid loading the initial_data fixture.
+
test <app or test identifier>
-----------------------------
View
54 tests/modeltests/fixtures_model_package/tests.py
@@ -20,6 +20,60 @@ def testClassFixtures(self):
)
+class TestNoInitialDataLoading(TestCase):
+ def test_syncdb(self):
+ Book.objects.all().delete()
+
+ management.call_command(
+ 'syncdb',
+ verbosity=0,
+ commit=False
+ )
+ self.assertQuerysetEqual(
+ Book.objects.all(), [
+ u'Achieving self-awareness of Python programs'
+ ],
+ lambda a: a.name
+ )
+
+ Book.objects.all().delete()
+
+ management.call_command(
+ 'syncdb',
+ verbosity=0,
+ commit=False,
+ load_initial_data=False
+ )
+ self.assertQuerysetEqual(Book.objects.all(), [])
+
+ def test_flush(self):
+ Book.objects.all().delete()
+
+ management.call_command(
+ 'flush',
+ verbosity=0,
+ interactive=False,
+ commit=False
+ )
+ self.assertQuerysetEqual(
+ Book.objects.all(), [
+ u'Achieving self-awareness of Python programs'
+ ],
+ lambda a: a.name
+ )
+
+ Book.objects.all().delete()
+
+ management.call_command(
+ 'flush',
+ verbosity=0,
+ commit=False,
+ interactive=False,
+ load_initial_data=False
+ )
+ self.assertQuerysetEqual(Book.objects.all(), [])
+
+
class FixtureTestCase(TestCase):
def test_initial_data(self):
"Fixtures can load initial data into models defined in packages"
Please sign in to comment.
Something went wrong with that request. Please try again.