Skip to content

Django Integration

DevDb Pro provides zero-config database discovery for Django projects, automatically reading your settings.py configuration to connect to your database.

Zero-Config Discovery

DevDb automatically detects Django databases from your project configuration.

How It Works

  1. Open a Django project in VS Code
  2. DevDb reads settings.py
  3. Extracts database config from DATABASES setting
  4. Auto-connects to your database

Requirements

  • Django project with settings.py
  • Standard DATABASES configuration
  • Database server running and accessible

Supported Databases

DevDb works with these Django database backends:

  • SQLite (django.db.backends.sqlite3)
  • MySQL (django.db.backends.mysql)
  • PostgreSQL (django.db.backends.postgresql)

Configuration Examples

SQLite

settings.py:

python
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}

DevDb automatically connects to the SQLite file.

MySQL

settings.py:

python
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'myapp',
        'USER': 'root',
        'PASSWORD': 'secret',
        'HOST': '127.0.0.1',
        'PORT': '3306',
    }
}

DevDb reads credentials and connects to MySQL.

PostgreSQL

settings.py:

python
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'myapp',
        'USER': 'postgres',
        'PASSWORD': 'secret',
        'HOST': 'localhost',
        'PORT': '5432',
    }
}

DevDb connects to PostgreSQL automatically.

Multiple Databases

Django supports multiple database connections:

settings.py:

python
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'main_db',
        'USER': 'postgres',
        'PASSWORD': 'secret',
        'HOST': 'localhost',
    },
    'analytics': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'analytics_db',
        'USER': 'root',
        'PASSWORD': 'secret',
        'HOST': '127.0.0.1',
    }
}

DevDb detects and lists both databases:

  • main_db (PostgreSQL)
  • analytics_db (MySQL)

Switch between them in the DevDb sidebar.

Environment Variables

For Django projects using environment variables:

settings.py:

python
import os

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': os.environ.get('DB_NAME', 'myapp'),
        'USER': os.environ.get('DB_USER', 'postgres'),
        'PASSWORD': os.environ.get('DB_PASSWORD'),
        'HOST': os.environ.get('DB_HOST', 'localhost'),
        'PORT': os.environ.get('DB_PORT', '5432'),
    }
}

DevDb resolves environment variables from:

  • System environment
  • .env files (if using python-dotenv)
  • VS Code launch configurations

Features

Database Client

Full Database Client features:

  • Browse tables and data
  • Inline editing
  • Schema viewer
  • JSON preview

Quick Table Access

Use Cmd+K Cmd+G (Mac) or Ctrl+K Ctrl+G (Windows/Linux):

  • Quickly open any Django model table
  • Search across all databases
  • Instant navigation

Context Menu

Right-click table/model names in code:

  • "Open table at cursor" - View table in DevDb
  • Works with model class names
  • Works with db_table meta options

Example:

python
# Right-click "User" and select "DevDb > Open table at cursor"
class User(models.Model):
    username = models.CharField(max_length=150)
    email = models.EmailField()

    class Meta:
        db_table = 'auth_user'  # Also works

Data Export

Export table data:

  • JSON format - For fixtures or testing
  • SQL format - For migrations or backups
  • Copy to clipboard or save to file

Workflow Examples

Example 1: Inspect Models

After creating models and running migrations:

  1. Run migrations: python manage.py migrate
  2. Open DevDb (Cmd+K Cmd+D or Ctrl+K Ctrl+D)
  3. Browse tables to verify schema
  4. Check indexes in Schema tab
  5. Add test data directly

Example 2: Debug Data Issues

When investigating data problems:

  1. Open relevant model in code
  2. Right-click model name → "Open table at cursor"
  3. Browse actual data in database
  4. Edit test records to reproduce issue
  5. Verify fix by refreshing data

Example 3: Create Fixtures

Generate test fixtures:

  1. Create test data in DevDb
  2. Export as JSON using Data Export
  3. Save to fixtures folder: myapp/fixtures/
  4. Load in tests: python manage.py loaddata fixture.json

Example 4: Migration Verification

After writing migrations:

  1. Apply migration: python manage.py migrate
  2. Refresh DevDb connection
  3. View schema changes in Schema tab
  4. Verify constraints and indexes
  5. Test with sample data

Django-Specific Features

Model Table Names

DevDb handles Django's table naming:

Default naming (appname_modelname):

python
class Product(models.Model):  # Table: myapp_product
    pass

Custom naming:

python
class Product(models.Model):
    class Meta:
        db_table = 'products'  # Table: products

DevDb recognizes both patterns.

Auth Tables

Django auth tables are auto-detected:

  • auth_user
  • auth_group
  • auth_permission
  • etc.

Browse and edit as needed.

Migration History

View migration history:

  • Open django_migrations table
  • See applied migrations
  • Check timestamps
  • Verify migration order

Troubleshooting

Database Not Detected

If DevDb doesn't find your Django database:

  1. Check settings.py exists in workspace
  2. Verify DATABASES config is present
  3. Ensure database is running
  4. Reload VS Code window

Connection Fails

If connection doesn't work:

  1. Test Django connection: python manage.py dbshell
  2. Check credentials in settings.py
  3. Verify database server is accessible
  4. Review environment variables

Settings File Location

For non-standard settings locations:

  1. DevDb searches common patterns:

    • settings.py
    • myproject/settings.py
    • config/settings.py
  2. If not found, use manual configuration

Docker/Container Setup

For containerized Django:

  1. Expose database port in docker-compose.yml
  2. Use host port in settings.py
  3. DevDb connects to exposed port
  4. Or use VS Code dev containers

Best Practices

Development

  1. Use separate databases for dev and test
  2. Keep sensitive data out of settings.py (use env vars)
  3. Add database dumps to .gitignore
  4. Export fixtures for test data

Team Collaboration

  1. Document database setup in README
  2. Share sample .env file (.env.example)
  3. Use consistent database versions
  4. Export seed data for onboarding

Security

  1. Never commit credentials to git
  2. Use environment variables for sensitive data
  3. Exclude .devdbrc from version control
  4. Sanitize exports before sharing

Integration with Other Tools

Django Admin

Use DevDb alongside Django Admin:

  • DevDb for quick data inspection
  • Django Admin for complex operations
  • Export from DevDb to JSON for admin fixtures

Django Debug Toolbar

Combine with Debug Toolbar:

  • Debug Toolbar shows queries
  • DevDb lets you inspect data
  • Export queries to test in DevDb

Testing

Use DevDb for test data:

  1. Create test data in DevDb
  2. Export as fixture
  3. Load in tests with loaddata
  4. Verify results in DevDb

Next Steps

DevDb Pro - Zero-config database management for VS Code