1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #21969: Fix behaviour of initial_data with migrated apps

This commit is contained in:
Andrew Godwin
2014-02-09 12:22:29 +00:00
parent 250841017c
commit d5df7a0515
5 changed files with 48 additions and 2 deletions

View File

@@ -35,6 +35,8 @@ class Command(BaseCommand):
make_option('--database', action='store', dest='database',
default=DEFAULT_DB_ALIAS, help='Nominates a specific database to load '
'fixtures into. Defaults to the "default" database.'),
make_option('--app', action='store', dest='app_label',
default=None, help='Only look for fixtures in the specified app.'),
make_option('--ignorenonexistent', '-i', action='store_true', dest='ignore',
default=False, help='Ignores entries in the serialized data for fields'
' that do not currently exist on the model.'),
@@ -44,6 +46,8 @@ class Command(BaseCommand):
self.ignore = options.get('ignore')
self.using = options.get('database')
self.app_label = options.get('app_label')
self.hide_empty = options.get('hide_empty', False)
if not len(fixture_labels):
raise CommandError(
@@ -105,7 +109,9 @@ class Command(BaseCommand):
cursor.execute(line)
if self.verbosity >= 1:
if self.fixture_object_count == self.loaded_object_count:
if self.fixture_count == 0 and self.hide_empty:
pass
elif self.fixture_object_count == self.loaded_object_count:
self.stdout.write("Installed %d object(s) from %d fixture(s)" %
(self.loaded_object_count, self.fixture_count))
else:
@@ -230,6 +236,8 @@ class Command(BaseCommand):
"""
dirs = []
for app_config in apps.get_app_configs():
if self.app_label and app_config.label != self.app_label:
continue
d = os.path.join(app_config.path, 'fixtures')
if os.path.isdir(d):
dirs.append(d)

View File

@@ -278,7 +278,8 @@ class Command(BaseCommand):
# Load initial_data fixtures (unless that has been disabled)
if self.load_initial_data:
call_command('loaddata', 'initial_data', verbosity=self.verbosity, database=connection.alias, skip_validation=True)
for app_label in app_labels:
call_command('loaddata', 'initial_data', verbosity=self.verbosity, database=connection.alias, skip_validation=True, app_label=app_label, hide_empty=True)
return created_models