Database diagrams
Available only in PyCharm Professional: download to try or compare editions
In the Database tool window, right-click a database object and select Diagrams | Show Diagram
This functionality relies on the Database Tools and SQL plugin, which is bundled and enabled in PyCharm by default. If the relevant features are not available, make sure that you did not disable the plugin.
note
The Database Tools and SQL plugin is available only in PyCharm Professional.
Press CtrlAlt0S to open settings and then select Plugins.
Open the Installed tab, find the Database Tools and SQL plugin, and select the checkbox next to the plugin name.
This functionality relies on the Diagrams plugin, which is bundled and enabled in PyCharm by default. If the relevant features are not available, make sure that you did not disable the plugin.
Press CtrlAlt0S to open settings and then select Plugins.
Open the Installed tab, find the Diagrams plugin, and select the checkbox next to the plugin name.
Database diagrams graphically show the structure of the database and relations between database objects. You can generate a diagram for a data source, a schema, or a table. To create relations between database objects, consider using primary and foreign keys.
You can save the generated diagrams in two formats: UML and PNG. The UML format is an internal format developed specifically for PyCharm. It is not supported by other products. If you want to share the created diagram, consider using PNG.
Also, you can build execution plans. An execution plan is a set of steps that were used to access data in a database. For more information about creating an execution plan, refer to Visualize a query plan.
In the Database tool window (View | Tool Windows | Database) , right-click a database object and select Diagrams | Show Diagram.
To pan and zoom the diagram, use your touchpad, scroll bars or the mouse wheel for vertical scrolling and Shift + mouse wheel for horizontal scrolling. You can also use Shift + mouse wheel for zooming.
To use the magnifier tool, keep the Alt key pressed and hover over the desired areas of the diagram. Use the mouse wheel to extra zoom the diagram area within the magnifier tool.
Generate a diagram. For more information about generating a diagram, refer to Generate a diagram for a database object.
Click the Comments button ().
In the Database tool window (View | Tool Windows | Database) , right-click an object and select Tools | Set Color.
Select a color and click OK. Refresh the diagram to apply the color by clicking the Refresh button ().
In PyCharm, you can export a diagram in various formats to a file, to clipboard, and open it in a web editor. You can also print a diagram and save it as an image. To do that, use the corresponding actions in the context menu of your diagram.
To export your diagram to a third-party editor in web browser, right-click the diagram, navigate to Export Diagram | Open in Web Editor, and select the editor.
Alternatively, click the Export Diagram button () on the diagram toolbar, and select the editor in the corresponding submenu.
The supported editors are as follows:
To copy your diagram to clipboard, right-click the diagram, navigate to Export Diagram | Copy to Clipboard, and select the format.
Alternatively, click the Export Diagram button () on the diagram toolbar, and select the format in the corresponding submenu.
The supported formats are as follows:
Mermaid
classDiagram
{...}PlantUML
@startuml
{...}Graphviz DOT
digraph "sakila" {
{...}Graphviz DOT with Positions
digraph "sakila" {
{...}
To export your diagram to a file, right-click the diagram, navigate to Export Diagram | Export to File, and select the format.
Alternatively, click the Export Diagram button () on the diagram toolbar, and select the format in the corresponding submenu.
The supported formats are as follows:
YEd .graphml
JGraph .drawio
Graphviz .dot
Graphviz .dot with Positions
Mermaid .md
PlantUML
IDEA .uml: The UML format
is an internal format supported only by PyCharm. To open the saved diagram, drag the UML file to the editor.
To export your diagram as an image in PNG format, right-click the diagram and select Export Diagram | Export to Image.
Alternatively, click the Export Diagram button () on the diagram toolbar, and select Export to Image.
Possible icon combinations for columns in diagrams:
Icon | Foreign key | Primary key | Indexed | NOT NULL |
---|---|---|---|---|
To configure the default visibility settings and layout for diagrams, Open settings by pressing CtrlAlt0S and navigate to Tools | Diagrams. .
For more information about database diagrams configuration settings, refer to the Diagrams reference topic.
Use the diagram editor toolbar to quickly access actions and the context menu to manage the displayed diagram.
Item | Description |
---|---|
(Available when you work with databases.) Click this button to show primary key columns in the diagram. | |
(Available when you work with databases.) Toggles the display of the following:
| |
(Available when you work with databases.) Click this button to hide or show virtual foreign keys in the diagram. | |
(Available when you work with databases.) Click this button to hide or show comments in the diagram. | |
| Click this icon to increase the scale of the diagram. Alternatively, press NumPad +. |
| Click this icon to decrease the scale of the diagram. Alternatively, press NumPad -. |
| Click this icon to restore the actual size of the diagram. |
Click this icon to make the contents fit into the current diagram size. | |
Click this icon to apply the current layout, selected from the Layout node of the diagram context menu. | |
Click this icon to scale the diagram to the edges of the window. | |
Click this icon to copy the diagram into the clipboard. | |
Click this icon and then select any diagram area with the mouse: the selected area will be copied into the clipboard. | |
Click this icon to export the current diagram to the PNG format. | |
Click this icon to print the diagram. |
The table below contains commands that are not available from the toolbar.
Item | Description |
---|---|
Selected Element Actions | Use this option to open a list of actions that is applied to a selected element in the diagram. You can select actions to copy an element, jump to its source, find its usages, use the Navigate actions, various Git actions, and so on. |
Content | Use this option to open a list of actions that help you to add new elements, show dependencies, sort elements inside the diagram, and so on.
|
Delete | Deletes the selected diagram. |
Analyze Graph | Use this node to select one of the commands to analyze a diagram. You can check the graph characteristics, change the focus of the graph, measure graph centrality, and so on. |
Layout | Select the desired diagram layout from the submenu. |
Orientation | Provides you with the following orientation options: Bottom to Top, Top to Bottom, and so on. |
Apply Current Layout | Applies the current layout, selected from the Layout node of the diagram context menu |
Route Edges | Scales the diagram content to the edges of the diagram window. |
Appearance | Manages the way the diagram is presented by showing the grid, edge labels, bridges. Allows you to merge edges and select edge shapes. |
Behavior | Use this option to select commands related to the diagram behavior sucha as aligning elements against the grid, showing structure view for the selected node, or fitting the content after the layout. |
Export Diagram | You can select and configure the following options:
|
Thanks for your feedback!