{"id":9687,"library":"django-sql-explorer","title":"Django SQL Explorer","description":"Django SQL Explorer provides a delightful SQL editor and interface for writing and sharing SQL queries directly within a Django admin-like environment. It allows users to quickly generate reports, download data, and visualize results, with recent versions (like 5.3) adding AI assistance for query generation. It is actively maintained, with new releases often coinciding with major Django version compatibility updates.","status":"active","version":"5.3","language":"en","source_language":"en","source_url":"https://github.com/smore-co/django-sql-explorer","tags":["django","sql","reporting","admin","data-analysis","business-intelligence"],"install":[{"cmd":"pip install django-sql-explorer","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"django-sql-explorer is a Django application and requires a Django project to run.","package":"Django","optional":false}],"imports":[{"note":"The PyPI package is `django-sql-explorer` but the Django application name is simply `explorer`.","wrong":"INSTALLED_APPS = ['django_sql_explorer', ...]","symbol":"Add to INSTALLED_APPS","correct":"INSTALLED_APPS = ['explorer', ...]"},{"note":"Use the `explorer` app's URLs, typically under the `/explorer/` path.","wrong":"path('sql-explorer/', include('django_sql_explorer.urls'))","symbol":"Include URLs","correct":"from django.urls import include, path\n\nurlpatterns = [\n    path('explorer/', include('explorer.urls')),\n    # ... other url patterns\n]"},{"note":"For programmatic access to saved queries.","symbol":"Query Model","correct":"from explorer.models import Query"}],"quickstart":{"code":"import os\n\n# settings.py\n# Minimum settings for django-sql-explorer\n\nDEBUG = True\n\nSECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', 'a-very-secret-key-for-dev')\n\nINSTALLED_APPS = [\n    'django.contrib.admin',\n    'django.contrib.auth',\n    'django.contrib.contenttypes',\n    'django.contrib.sessions',\n    'django.contrib.messages',\n    'django.contrib.staticfiles',\n    'explorer', # Add explorer app\n]\n\nMIDDLEWARE = [\n    'django.middleware.security.SecurityMiddleware',\n    'django.contrib.sessions.middleware.SessionMiddleware',\n    'django.middleware.common.CommonMiddleware',\n    'django.middleware.csrf.CsrfViewMiddleware',\n    'django.contrib.auth.middleware.AuthenticationMiddleware',\n    'django.contrib.messages.middleware.MessageMiddleware',\n    'django.middleware.clickjacking.XFrameOptionsMiddleware',\n]\n\nROOT_URLCONF = 'myproject.urls'\n\nTEMPLATES = [\n    {\n        'BACKEND': 'django.template.backends.django.DjangoTemplates',\n        'DIRS': [],\n        'APP_DIRS': True,\n        'OPTIONS': {\n            'context_processors': [\n                'django.template.context_processors.debug',\n                'django.template.context_processors.request',\n                'django.contrib.auth.context_processors.auth',\n                'django.contrib.messages.context_processors.messages',\n            ],\n        },\n    },\n]\n\nWSGI_APPLICATION = 'myproject.wsgi.application'\n\nDATABASES = {\n    'default': {\n        'ENGINE': 'django.db.backends.sqlite3',\n        'NAME': os.path.join(os.getcwd(), 'db.sqlite3'),\n    }\n}\n\nAUTH_PASSWORD_VALIDATORS = [\n    {'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator'},\n    {'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator'},\n    {'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator'},\n    {'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator'},\n]\n\nLANGUAGE_CODE = 'en-us'\nTIME_ZONE = 'UTC'\nUSE_I18N = True\nUSE_L10N = True\nUSE_TZ = True\n\nSTATIC_URL = '/static/'\n\n# explorer specific settings (optional, defaults to is_staff checks)\nEXPLORER_PERMISSION_VIEW = lambda request: request.user.is_staff\nEXPLORER_PERMISSION_CHANGE = lambda request: request.user.is_superuser\n\n# myproject/urls.py\n# from django.contrib import admin\n# from django.urls import include, path\n# \n# urlpatterns = [\n#     path('admin/', admin.site.urls),\n#     path('explorer/', include('explorer.urls')), # Add explorer URLs\n# ]\n\n# To run:\n# 1. pip install django django-sql-explorer\n# 2. Create a Django project and app (e.g., 'myproject')\n# 3. Replace myproject/settings.py and myproject/urls.py with the relevant parts above\n# 4. python manage.py migrate\n# 5. python manage.py createsuperuser\n# 6. python manage.py runserver\n# 7. Navigate to http://127.0.0.1:8000/explorer/ and log in with your superuser account.","lang":"python","description":"To set up Django SQL Explorer, first ensure you have Django installed. Then, install `django-sql-explorer` via pip. Add `'explorer'` to your `INSTALLED_APPS` in `settings.py` and include `explorer.urls` in your project's `urls.py`. Run `python manage.py migrate` to create Explorer's database tables. Access is typically restricted to staff or superusers by default. Navigate to `/explorer/` after running the development server and log in with an appropriate user."},"warnings":[{"fix":"Upgrade `django-sql-explorer` to the latest version (`pip install --upgrade django-sql-explorer`) to ensure compatibility with recent Django releases. If specific compatibility is needed, consult the release notes.","message":"Major Django version compatibility: Ensure your `django-sql-explorer` version is compatible with your Django version. For example, older versions of explorer might not work correctly with Django 3.x, 4.x, or 5.x. Check the project's `setup.py` or documentation for `requires_django`.","severity":"breaking","affected_versions":"< 3.0 (Django 2.x), < 4.0 (Django 3.x)"},{"fix":"Explicitly define `EXPLORER_PERMISSION_VIEW` and `EXPLORER_PERMISSION_CHANGE` in `settings.py` to match your organization's security policies. For example, `EXPLORER_PERMISSION_VIEW = lambda request: request.user.groups.filter(name='Data Analysts').exists()`.","message":"Security Risk: Granting SQL access is powerful. Ensure `EXPLORER_PERMISSION_VIEW` and `EXPLORER_PERMISSION_CHANGE` settings are configured carefully. By default, these check `request.user.is_staff` and `request.user.is_superuser` respectively, but can be customized to any callable that returns True/False.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If querying a specific non-default database is required, consider configuring that database as the 'default' for a separate explorer instance, or use Django's database routing feature to direct `explorer`'s queries to a specific database if you have custom logic.","message":"Database Connections: `django-sql-explorer` uses your Django project's default database connection. If you have multiple databases configured, you need to be mindful of which database it's querying. It does not natively support switching between multiple configured databases within the explorer UI, though custom solutions or proxy views could achieve this.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure you are using `path('explorer/', include('explorer.urls'))` in your project's `urls.py`. Always refer to the official documentation for the version you are using for the correct URL configuration.","message":"Old URL patterns: In very old versions (<3.0), the URL inclusion pattern or some view names might have been different, leading to `NoReverseMatch` errors.","severity":"deprecated","affected_versions":"< 3.0"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Ensure `pip install django-sql-explorer` has been run and add `'explorer'` to your `INSTALLED_APPS` list in `settings.py`.","cause":"The `explorer` app was not added to `INSTALLED_APPS` in your Django `settings.py`, or `django-sql-explorer` was not installed.","error":"ModuleNotFoundError: No module named 'explorer'"},{"fix":"In your project's `urls.py`, add `path('explorer/', include('explorer.urls'))` to your `urlpatterns`.","cause":"The `explorer.urls` are not correctly included in your project's `urls.py`.","error":"django.urls.exceptions.NoReverseMatch: Reverse for 'explorer:query_list' not found. 'explorer' is not a registered namespace."},{"fix":"Run `python manage.py migrate` to create the necessary database tables for the explorer app.","cause":"The database migrations for `django-sql-explorer` have not been run.","error":"django.db.utils.OperationalError: no such table: explorer_query"}]}