Edit a Mermaid ER diagram on the canvas in Manual mode
Move entities, draw relationships, pick the cardinality at each end, and edit attributes and keys with the mouse, while Flowgraph Studio writes the Mermaid erDiagram code for you.
Typing an ER diagram is quick once you know the syntax. Rearranging one is not: Mermaid places the entities itself, and changing ||--o{ to }|..|{ means remembering which symbol sits on which side. Manual mode lets you make those changes on the drawing. Every change is written into the Mermaid code, so the code stays the diagram's source and works in any other Mermaid tool.
Switch to Manual mode
Open an ER diagram in Flowgraph Studio and switch the toggle in the top bar from Code to Manual. The code panel stays open beside the canvas, so you can watch each edit appear in the text. A toolbar at the top left adds an entity or hands the layout back to Mermaid, and a bar at the top of the canvas shows the fields for whatever you select.
Start from this diagram if you want to follow along:
erDiagram
CUSTOMER ||--o{ PURCHASE_ORDER : places
PURCHASE_ORDER ||--|{ ORDER_ITEM : contains
CUSTOMER {
int id PK
string email UK
}
PURCHASE_ORDER {
int id PK
int customer_id FK
date placed_on
}
ORDER_ITEM {
int id PK
int order_id FK
int quantity
}You can select three kinds of thing:
- An entity: click its name.
- An attribute: click its row.
- A relationship: click the line or its label.
Double-click any of them to select it and start typing in its main field. Escape, or a click on empty canvas, clears the selection.
Move entities
Drag an entity to move it. Until you move one, Mermaid arranges the diagram on every redraw, and the Layout settings (engine, direction, spacing) apply. The first drag saves every entity's position, so moving one box doesn't make the others jump.
Mermaid has no syntax for positions, so they're kept in one comment line at the end of the code:
%% flowgraph-layout: {"v":1,"nodes":{"CUSTOMER":{"x":120,"y":80}, …}}
Other Mermaid tools ignore the line and lay the diagram out themselves. In Flowgraph Studio, exports, shared links, and the render API keep your arrangement. Auto layout in the toolbar removes the saved positions and lets Mermaid arrange everything again; it asks first, because your arrangement is replaced.
Add entities and relationships
- Entity in the toolbar adds an entity in the middle of the view. It's named
ENTITY(thenENTITY_2, and so on), starts with anint id PKattribute, and its name field is ready for typing. - Select an entity and four + handles appear around it. Click a + to add a new entity, already related to the selected one.
- Drag a + onto another entity to relate the two. Drop it on empty canvas instead to add a related entity there.
Once you've moved an entity, new entities go where you asked: on the side of the + you clicked, or where you dropped it. Before that, Mermaid places them along with everything else.
A new relationship starts as exactly one on the selected entity's side and zero or more on the other, with a solid line and no label. The label field is focused, so type a verb such as places straight away. In the code it's an ordinary line:
CUSTOMER ||--o{ INVOICE : "receives"
Set cardinality, line style, and label
Select a relationship and the bar reads like a sentence: the first entity, how many of it, the line style, how many of the second entity, then the second entity.
- How many at each end: Zero or one, Exactly one, Zero or more, or One or more. Each menu sets the marker drawn at that entity's end of the line.
- Line: Identifying (solid) when the child can't be identified without the parent, typically because the foreign key is part of its primary key; Non-identifying (dashed) otherwise.
- Label: the words written on the line. Spaces are fine; the code quotes them.
- Swap the two ends reverses the line and its markers together, so the meaning stays the same while the order in the code changes.
Read the result aloud before moving on: "each purchase order has exactly one customer; a customer places zero or more purchase orders". If the sentence is wrong, the menus are the quickest place to fix it. The ER relationship cheat sheet lists every symbol these menus write.
Rename entities and edit attributes
Select an entity to rename it. A plain name (letters, digits, _ and -) renames it everywhere: its block, every relationship that uses it, style and class lines, and its saved position. A name with spaces, such as Purchase order, becomes a display name instead, PURCHASE_ORDER["Purchase order"], so the relationships keep using the short name. + Attribute adds a string column row and selects it.
Select an attribute row to edit it:
- Type and Name are single words, as Mermaid requires.
varchar(255)andstring[]are fine; if you type something Mermaid can't read, the field goes back to what the code says. - PK, FK, and UK toggle primary, foreign, and unique keys. An attribute can have several, such as
int order_id PK, FKin a junction table. - Comment adds a quoted note after the keys, such as
"ISO 4217 code". - The arrows move the attribute up or down within its entity.
Delete and undo
Delete or Backspace removes the selection: an attribute, a relationship, or an entity. Deleting an entity also removes its relationships, its style and class lines, and its saved position. Ctrl+Z and Ctrl+Y (⌘Z and ⇧⌘Z on a Mac) undo and redo in the canvas and the code panel alike, since every canvas edit is a code edit.
What stays as you wrote it
Manual mode only changes the lines an edit is about. Comments, blank lines, indentation, title and accessibility lines, and styling stay as they are. If a relationship uses syntax manual mode can't edit yet, the hint at the top of the canvas says so and that line is left alone; edit it in the code panel.
Positions are the one thing Mermaid can't express, so a diagram you've arranged by hand looks different in a Markdown file on GitHub. That's usually fine: the entities and relationships are the same, only their placement differs. Keep the layout line if you want Flowgraph exports to match what you see; delete it if you'd rather every tool agree.
For other ways to edit the same diagram, typing and asking the AI assistant, see Edit Mermaid diagrams by dragging, typing, or asking. To start from an existing database rather than a blank canvas, convert SQL to an ER diagram and arrange the result in Manual mode.
More guides
- Edit Mermaid diagrams visually in VS CodeDrag, connect and restyle a Mermaid diagram on Flowgraph's canvas inside VS Code, and every change is written back into the .mmd file or Markdown block as ordinary code.
- Keep a diagram's style in its code with %% flowgraph-themeOne comment line keeps a Mermaid diagram's Flowgraph theme in the file, so it looks the same in your repository, in VS Code, from the CLI and through the render API.
- Preview Flowgraph diagrams in VS Code, with icons, layout and your themeInstall the Flowgraph Studio extension to preview Mermaid files and Markdown blocks in VS Code as Flowgraph draws them, see mistakes in plain words, and export SVG or PNG.