-
Notifications
You must be signed in to change notification settings - Fork 2
Foreign Key Navigation
Foreign Key Navigation is a powerful feature in D1 Database Manager that allows you to seamlessly navigate between related tables by clicking on foreign key values. This feature dramatically improves workflow efficiency when exploring relational data.
When viewing table data, columns that are foreign keys are automatically detected and displayed as clickable links with visual indicators. Clicking a foreign key value instantly navigates to the referenced table with an automatic filter applied to show only the related records.
- Foreign key columns are automatically identified using
PRAGMA foreign_key_list() - FK values display as interactive buttons with a link icon (π)
- Hover tooltips show the referenced table and column (e.g., "References customers.id")
- NULL foreign key values are not clickable and display as regular NULL values
The breadcrumb navigation appears at the top of the table view when you've navigated via foreign keys:
Database > orders > customers > addresses
- Home Icon: Click the database name to return to the database table list
- Table Segments: Each table in your navigation path is clickable
- Current Table: The current table is highlighted and non-clickable
- Overflow Handling: Only the last 5 tables are shown; earlier tables are indicated with "..."
When you navigate via a foreign key:
- The target table automatically opens
- A filter is applied to the referenced column matching the clicked value
- The filter bar shows automatically with the applied filter
- You see only the relevant records related to your starting point
Example: Click customer_id = 42 in the orders table:
- Navigates to the
customerstable - Automatically filters to
WHERE id = 42 - Shows only the customer with ID 42
- Alt + Left Arrow: Navigate back to the previous table in your history
- Works at any depth in your navigation history
- Preserves filters from each navigation step
Foreign key columns are visually distinct:
- Link Icon (π): Indicates the column is a foreign key
- Blue Border: FK values have a subtle blue border
- Hover Effect: Highlights on hover to indicate clickability
- Primary Color: FK values use the primary theme color
When you open a table view:
PRAGMA foreign_key_list("table_name")This query returns all foreign key relationships for the table, which the UI uses to identify FK columns.
Example Scenario: E-commerce database
products (id, category_id, supplier_id)
ββ category_id β categories(id)
ββ supplier_id β suppliers(id)
orders (id, customer_id, product_id)
ββ customer_id β customers(id)
ββ product_id β products(id)
User Action: View the orders table and click customer_id = 15
-
Detects:
customer_idis FK tocustomers.id -
Navigates: To
customerstable -
Filters:
WHERE id = 15 -
Updates History:
ordersβcustomers -
Shows Breadcrumb:
Database > orders > customers
Next: From customers, click address_id = 203
-
Navigates: To
addressestable -
Filters:
WHERE id = 203 -
Updates History:
ordersβcustomersβaddresses -
Shows Breadcrumb:
Database > orders > customers > addresses
You can navigate back using:
- Breadcrumb Segments: Click any table name in the breadcrumb
- Back Button: Arrow icon in the breadcrumb bar
- Keyboard: Alt + Left Arrow
- Header Back Button: Returns to the database table list (clears history)
Navigate through related records without writing queries:
orders β customers β addresses β countries
Track a full customer journey from order to their location.
Verify foreign key relationships are correct:
- View an order with
customer_id = 99 - Click the FK to see if customer 99 exists
- Verify the customer data is correct
Follow data trails for auditing purposes:
invoices β orders β line_items β products β categories
Trace an invoice back to its product categories.
When investigating a customer issue:
support_tickets β customers β orders β payments
Quickly access all related information about a customer.
- Behavior: NULL FK values are not clickable
- Display: Shows as gray italic "NULL" text
- Reason: No target record to navigate to
- Current Support: Each column in a composite FK is clickable individually
- Future: May add grouped navigation for composite FKs
-
Support: Works correctly (e.g.,
employees.manager_id β employees.id) - Navigation: Can navigate from employee to their manager in the same table
- Cycle Detection: Not currently implemented
- Current: No automatic cycle detection
- Behavior: You can navigate in circles indefinitely
- Workaround: Use breadcrumbs to return to a previous point
- Breadcrumb Display: Last 5 tables only
- Internal History: Up to 20 tables stored (prevents memory issues)
- Overflow: Older entries automatically removed
Instead of clicking back multiple times, click directly on the table you want in the breadcrumb trail.
After navigating via FK, you may want to see the entire target table:
- Click "Clear All" in the filter bar
- The breadcrumb history remains intact
FK filters and regular filters work together:
- Navigate via FK to get initial filter
- Add additional filters to narrow results further
Use Alt+Left repeatedly to quickly navigate back through your entire history.
The table subtitle shows: β’ Navigated from FK when you're in FK navigation mode.
The feature uses these endpoints:
GET /api/tables/:dbId/foreign-keys/:tableNameResponse:
{
"result": {
"foreignKeys": [
{
"column": "customer_id",
"refTable": "customers",
"refColumn": "id",
"onDelete": "CASCADE",
"onUpdate": "NO ACTION"
}
]
},
"success": true
}GET /api/tables/:dbId/data/:tableName?fkFilter=id:42The fkFilter parameter format: column:value
Possible Causes:
- Foreign key constraints not defined in the database
- Table has no foreign keys
- Value is NULL
Check: Run PRAGMA foreign_key_list("table_name") in the Query Console
Check:
- Referenced table exists in the database
- You have permissions to view the target table
- Browser console for JavaScript errors
Expected: Breadcrumbs only appear when navigationHistory has entries
- First table you view: No breadcrumb (starting point)
- After first FK navigation: Breadcrumb appears
Check:
-
fkFilterparameter in URL - Column name matches in target table
- Filter bar is enabled
- Timing: Runs once when table loads
- Caching: FK metadata is cached per table
- Impact: Minimal (<50ms typically)
- Instant UI Update: Navigation state changes immediately
- Data Load: Standard table data fetch time
- Filter Application: Server-side WHERE clause (efficient)
- History Limit: Max 20 tables prevents memory leaks
- Cleanup: Automatic removal of old entries
- Browser Storage: Not persisted (clears on page reload)
-
Column Names: Sanitized using
sanitizeIdentifier() - Filter Values: Properly escaped in WHERE clauses
- Validation: All inputs validated before query execution
- Table Access: Standard table permissions apply
- No Bypass: FK navigation doesn't grant additional permissions
- Auth Required: Same authentication as regular table access
Planned improvements to FK Navigation:
- Circular Dependency Detection: Warn users when navigating in cycles
- Composite FK Grouping: Navigate using multiple columns together
- Reverse Navigation: Quick links to see all records referencing current row
- Navigation History Export: Save navigation paths for documentation
- Smart Breadcrumb Shortcuts: Jump to commonly visited tables
- Foreign Key Dependencies - View all FK relationships before deletion
- Foreign Key Visualizer - Visual graph of all FK relationships
- ER Diagram - Entity-relationship diagram with FK connections
- Table Operations - General table management features
- Row Level Filtering - Advanced filtering options
Database schema:
CREATE TABLE customers (
id INTEGER PRIMARY KEY,
name TEXT
);
CREATE TABLE orders (
id INTEGER PRIMARY KEY,
customer_id INTEGER,
FOREIGN KEY (customer_id) REFERENCES customers(id)
);
CREATE TABLE order_items (
id INTEGER PRIMARY KEY,
order_id INTEGER,
product_id INTEGER,
FOREIGN KEY (order_id) REFERENCES orders(id),
FOREIGN KEY (product_id) REFERENCES products(id)
);Navigation Path:
- View
orderstable - Click
customer_id = 5β Navigates tocustomersfiltered to ID 5 - View customer details
- Use breadcrumb to return to
orders - Click different
customer_idto explore another customer
CREATE TABLE users (
id INTEGER PRIMARY KEY,
name TEXT
);
CREATE TABLE posts (
id INTEGER PRIMARY KEY,
user_id INTEGER,
FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE comments (
id INTEGER PRIMARY KEY,
post_id INTEGER,
user_id INTEGER,
FOREIGN KEY (post_id) REFERENCES posts(id),
FOREIGN KEY (user_id) REFERENCES users(id)
);Workflow: Investigate a comment
- Start at
commentstable - Click
user_idβ See who wrote the comment - Back to
comments - Click
post_idβ See the original post - From
posts, clickuser_idβ See post author - Breadcrumb shows:
Database > comments > posts > users
Foreign Key Navigation transforms the way you explore relational data in D1 Database Manager. By making foreign keys clickable and maintaining a breadcrumb trail, you can quickly traverse complex database relationships without writing a single SQL query.
Key Benefits:
- β‘ Faster data exploration
- π― Better understanding of relationships
- π Easier debugging and auditing
- π More intuitive user experience
- β¨οΈ Keyboard-friendly workflow
For questions or issues, visit the GitHub Issues page.
- Database Management
- R2 Backup Restore
- Scheduled Backups
- Table Operations
- Query Console
- Schema Designer
- Column Management
- Bulk Operations
- Job History
- Time Travel
- Read Replication
- Undo Rollback
- Foreign Key Visualizer
- ER Diagram
- Foreign Key Dependencies
- Foreign Key Navigation
- Circular Dependency Detector
- Cascade Impact Simulator
- AI Search
- FTS5 Full Text Search
- Cross Database Search
- Index Analyzer
- Database Comparison
- Database Optimization