diff --git a/django/core/management/commands/loaddata.py b/django/core/management/commands/loaddata.py index 356e2d08bd..4492e5c6cb 100644 --- a/django/core/management/commands/loaddata.py +++ b/django/core/management/commands/loaddata.py @@ -39,6 +39,12 @@ class Command(BaseCommand): connection = connections[using] self.style = no_style() + if not len(fixture_labels): + self.stderr.write( + self.style.ERROR("No database fixture specified. Please provide the path of at least one fixture in the command line.\n") + ) + return + verbosity = int(options.get('verbosity')) show_traceback = options.get('traceback') @@ -245,17 +251,13 @@ class Command(BaseCommand): transaction.commit(using=using) transaction.leave_transaction_management(using=using) - if fixture_object_count == 0: - if verbosity >= 1: - self.stdout.write("No fixtures found.\n") - else: - if verbosity >= 1: - if fixture_object_count == loaded_object_count: - self.stdout.write("Installed %d object(s) from %d fixture(s)\n" % ( - loaded_object_count, fixture_count)) - else: - self.stdout.write("Installed %d object(s) (of %d) from %d fixture(s)\n" % ( - loaded_object_count, fixture_object_count, fixture_count)) + if verbosity >= 1: + if fixture_object_count == loaded_object_count: + self.stdout.write("Installed %d object(s) from %d fixture(s)\n" % ( + loaded_object_count, fixture_count)) + else: + self.stdout.write("Installed %d object(s) (of %d) from %d fixture(s)\n" % ( + loaded_object_count, fixture_object_count, fixture_count)) # Close the DB connection. This is required as a workaround for an # edge case in MySQL: if the same connection is used to diff --git a/tests/regressiontests/fixtures_regress/tests.py b/tests/regressiontests/fixtures_regress/tests.py index 5c448e67b1..26e436b3c5 100644 --- a/tests/regressiontests/fixtures_regress/tests.py +++ b/tests/regressiontests/fixtures_regress/tests.py @@ -390,6 +390,21 @@ class TestFixtures(TestCase): stderr.getvalue().startswith('Problem installing fixture') ) + def test_loaddata_no_fixture_specified(self): + """ + Regression for #7043 - Error is quickly reported when no fixtures is provided in the command line. + """ + stderr = StringIO() + management.call_command( + 'loaddata', + verbosity=0, + commit=False, + stderr=stderr, + ) + self.assertEqual( + stderr.getvalue(), 'No database fixture specified. Please provide the path of at least one fixture in the command line.\n' + ) + class NaturalKeyFixtureTests(TestCase):