summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHasan Ramezani <hasan.r67@gmail.com>2019-06-30 01:35:48 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-07-01 13:47:54 +0200
commit5d03f2bc01fc08f57558cdd3b4fc08e6b379dad7 (patch)
tree14523e1acd9f7b94b4ff771a4d169d0f6e9b3e75
parentc2f381ef17058e5cfea58ae507983d2e459a2888 (diff)
Fixed #30595 -- Added error message when no objects found to sql* management commands.
-rw-r--r--django/core/management/commands/sqlflush.py5
-rw-r--r--django/core/management/commands/sqlmigrate.py2
-rw-r--r--django/core/management/commands/sqlsequencereset.py2
-rw-r--r--tests/empty_models/__init__.py0
-rw-r--r--tests/empty_models/models.py0
-rw-r--r--tests/empty_models/test_commands.py18
-rw-r--r--tests/migrations/test_commands.py6
-rw-r--r--tests/migrations/test_migrations_no_operations/0001_initial.py6
-rw-r--r--tests/migrations/test_migrations_no_operations/__init__.py0
9 files changed, 38 insertions, 1 deletions
diff --git a/django/core/management/commands/sqlflush.py b/django/core/management/commands/sqlflush.py
index 60e69e67bf..22e77254ea 100644
--- a/django/core/management/commands/sqlflush.py
+++ b/django/core/management/commands/sqlflush.py
@@ -19,4 +19,7 @@ class Command(BaseCommand):
)
def handle(self, **options):
- return '\n'.join(sql_flush(self.style, connections[options['database']], only_django=True))
+ sql_statements = sql_flush(self.style, connections[options['database']], only_django=True)
+ if not sql_statements and options['verbosity'] >= 1:
+ self.stderr.write('No tables found.')
+ return '\n'.join(sql_statements)
diff --git a/django/core/management/commands/sqlmigrate.py b/django/core/management/commands/sqlmigrate.py
index ba3bd708cc..f54a594a2c 100644
--- a/django/core/management/commands/sqlmigrate.py
+++ b/django/core/management/commands/sqlmigrate.py
@@ -63,4 +63,6 @@ class Command(BaseCommand):
# for it
plan = [(executor.loader.graph.nodes[targets[0]], options['backwards'])]
sql_statements = executor.collect_sql(plan)
+ if not sql_statements and options['verbosity'] >= 1:
+ self.stderr.write('No operations found.')
return '\n'.join(sql_statements)
diff --git a/django/core/management/commands/sqlsequencereset.py b/django/core/management/commands/sqlsequencereset.py
index d23f89ce1f..1d74ed9f55 100644
--- a/django/core/management/commands/sqlsequencereset.py
+++ b/django/core/management/commands/sqlsequencereset.py
@@ -20,4 +20,6 @@ class Command(AppCommand):
connection = connections[options['database']]
models = app_config.get_models(include_auto_created=True)
statements = connection.ops.sequence_reset_sql(self.style, models)
+ if not statements and options['verbosity'] >= 1:
+ self.stderr.write('No sequences found.')
return '\n'.join(statements)
diff --git a/tests/empty_models/__init__.py b/tests/empty_models/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/empty_models/__init__.py
diff --git a/tests/empty_models/models.py b/tests/empty_models/models.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/empty_models/models.py
diff --git a/tests/empty_models/test_commands.py b/tests/empty_models/test_commands.py
new file mode 100644
index 0000000000..5dd4744033
--- /dev/null
+++ b/tests/empty_models/test_commands.py
@@ -0,0 +1,18 @@
+import io
+
+from django.core.management import call_command
+from django.test import TestCase
+
+
+class CoreCommandsNoOutputTests(TestCase):
+ available_apps = ['empty_models']
+
+ def test_sqlflush_no_tables(self):
+ err = io.StringIO()
+ call_command('sqlflush', stderr=err)
+ self.assertEqual(err.getvalue(), 'No tables found.\n')
+
+ def test_sqlsequencereset_no_sequences(self):
+ err = io.StringIO()
+ call_command('sqlsequencereset', 'empty_models', stderr=err)
+ self.assertEqual(err.getvalue(), 'No sequences found.\n')
diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py
index a15ae461ce..4132b96be0 100644
--- a/tests/migrations/test_commands.py
+++ b/tests/migrations/test_commands.py
@@ -645,6 +645,12 @@ class MigrateTests(MigrationTestBase):
self.assertNotIn(start_transaction_sql.lower(), queries)
self.assertNotIn(connection.ops.end_transaction_sql().lower(), queries)
+ @override_settings(MIGRATION_MODULES={'migrations': 'migrations.test_migrations_no_operations'})
+ def test_migrations_no_operations(self):
+ err = io.StringIO()
+ call_command('sqlmigrate', 'migrations', '0001_initial', stderr=err)
+ self.assertEqual(err.getvalue(), 'No operations found.\n')
+
@override_settings(
INSTALLED_APPS=[
"migrations.migrations_test_apps.migrated_app",
diff --git a/tests/migrations/test_migrations_no_operations/0001_initial.py b/tests/migrations/test_migrations_no_operations/0001_initial.py
new file mode 100644
index 0000000000..a07dd888da
--- /dev/null
+++ b/tests/migrations/test_migrations_no_operations/0001_initial.py
@@ -0,0 +1,6 @@
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+ dependencies = []
+ operations = []
diff --git a/tests/migrations/test_migrations_no_operations/__init__.py b/tests/migrations/test_migrations_no_operations/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/migrations/test_migrations_no_operations/__init__.py