From 226ca7b5ce283e1f891dbbbefb0afaebdaa09f28 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Tue, 23 Dec 2025 19:34:32 -0500 Subject: Added DatabaseFeatures.supports_inspectdb. Needed by MongoDB. --- django/core/management/commands/inspectdb.py | 4 ++-- django/db/backends/base/features.py | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'django') diff --git a/django/core/management/commands/inspectdb.py b/django/core/management/commands/inspectdb.py index 06adfe39ed..8bd6c4bc0c 100644 --- a/django/core/management/commands/inspectdb.py +++ b/django/core/management/commands/inspectdb.py @@ -44,10 +44,10 @@ class Command(BaseCommand): ) def handle(self, **options): - try: + if connections[options["database"]].features.supports_inspectdb: for line in self.handle_inspection(options): self.stdout.write(line) - except NotImplementedError: + else: raise CommandError( "Database inspection isn't supported for the currently selected " "database backend." diff --git a/django/db/backends/base/features.py b/django/db/backends/base/features.py index 2031beaf8a..e8fa82aa21 100644 --- a/django/db/backends/base/features.py +++ b/django/db/backends/base/features.py @@ -400,6 +400,9 @@ class BaseDatabaseFeatures: supports_on_delete_db_default = True supports_on_delete_db_null = True + # Does the backend support the inspectdb management command? + supports_inspectdb = True + # Collation names for use by the Django test suite. test_collations = { "ci": None, # Case-insensitive. -- cgit v1.3