diff --git a/django/core/management/commands/dumpdata.py b/django/core/management/commands/dumpdata.py index 247b0f20fd..df9eecc0f8 100644 --- a/django/core/management/commands/dumpdata.py +++ b/django/core/management/commands/dumpdata.py @@ -144,7 +144,17 @@ class Command(BaseCommand): Collate the objects to be serialized. If count_only is True, just count the number of objects to be serialized. """ - models = serializers.sort_dependencies(app_list.items(), allow_cycles=True) + if use_natural_foreign_keys: + models = serializers.sort_dependencies(app_list.items(), allow_cycles=True) + else: + # There is no need to sort dependencies when natural foreign + # keys are not used. + models = [] + for (app_config, model_list) in app_list.items(): + if model_list is None: + models.extend(app_config.get_models()) + else: + models.extend(model_list) for model in models: if model in excluded_models: continue