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
- Open a Django project in VS Code
- DevDb reads
settings.py - Extracts database config from
DATABASESsetting - Auto-connects to your database
Requirements
- Django project with
settings.py - Standard
DATABASESconfiguration - 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:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}DevDb automatically connects to the SQLite file.
MySQL
settings.py:
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:
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:
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:
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
.envfiles (if usingpython-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_tablemeta options
Example:
# 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 worksData Export
- 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:
- Run migrations:
python manage.py migrate - Open DevDb (
Cmd+K Cmd+DorCtrl+K Ctrl+D) - Browse tables to verify schema
- Check indexes in Schema tab
- Add test data directly
Example 2: Debug Data Issues
When investigating data problems:
- Open relevant model in code
- Right-click model name → "Open table at cursor"
- Browse actual data in database
- Edit test records to reproduce issue
- Verify fix by refreshing data
Example 3: Create Fixtures
Generate test fixtures:
- Create test data in DevDb
- Export as JSON using Data Export
- Save to fixtures folder:
myapp/fixtures/ - Load in tests:
python manage.py loaddata fixture.json
Example 4: Migration Verification
After writing migrations:
- Apply migration:
python manage.py migrate - Refresh DevDb connection
- View schema changes in Schema tab
- Verify constraints and indexes
- Test with sample data
Django-Specific Features
Model Table Names
DevDb handles Django's table naming:
Default naming (appname_modelname):
class Product(models.Model): # Table: myapp_product
passCustom naming:
class Product(models.Model):
class Meta:
db_table = 'products' # Table: productsDevDb recognizes both patterns.
Auth Tables
Django auth tables are auto-detected:
auth_userauth_groupauth_permission- etc.
Browse and edit as needed.
Migration History
View migration history:
- Open
django_migrationstable - See applied migrations
- Check timestamps
- Verify migration order
Troubleshooting
Database Not Detected
If DevDb doesn't find your Django database:
- Check
settings.pyexists in workspace - Verify
DATABASESconfig is present - Ensure database is running
- Reload VS Code window
Connection Fails
If connection doesn't work:
- Test Django connection:
python manage.py dbshell - Check credentials in settings.py
- Verify database server is accessible
- Review environment variables
Settings File Location
For non-standard settings locations:
DevDb searches common patterns:
settings.pymyproject/settings.pyconfig/settings.py
If not found, use manual configuration
Docker/Container Setup
For containerized Django:
- Expose database port in docker-compose.yml
- Use host port in settings.py
- DevDb connects to exposed port
- Or use VS Code dev containers
Best Practices
Development
- Use separate databases for dev and test
- Keep sensitive data out of settings.py (use env vars)
- Add database dumps to
.gitignore - Export fixtures for test data
Team Collaboration
- Document database setup in README
- Share sample .env file (
.env.example) - Use consistent database versions
- Export seed data for onboarding
Security
- Never commit credentials to git
- Use environment variables for sensitive data
- Exclude
.devdbrcfrom version control - 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:
- Create test data in DevDb
- Export as fixture
- Load in tests with
loaddata - Verify results in DevDb
Next Steps
- Database Client - Master the interface
- Quick Table Access - Navigate efficiently
- Data Export - Export fixtures
- Configuration - Manual setup if needed