How to generate an AI ERD (Entity Relationship Diagram)
Step-by-step guide on generating an ERD
- Write a prompt describing the data model in detail. A simple one-liner (e.g. "draw a data model of a Twitter clone") can work too but the best prompts are usually at least 3-4 sentences long. Applying the below framework generally yields good results:
- First, write out the entities (i.e. tables). For the entities, you may want to specify attributes (i.e. columns) and their data types. You can also specify primary and foreign keys.
- Then, write out the relationship between tables including the relationship cardinality.(e.g. "the user entity and the document entity have a one-to-many relationship via the userId attribute")
- Generate a diagram with the completed prompt.
- Edit the diagram with follow-up prompts (this step requires signing in to Eraser).
Tips on generating an ERD
- If available, instead of writing a prompt from scratch, consider pasting excerpts from existing code (e.g. SQL schema, ORM schema), call transcripts, requirements docs, or image files.
- Iterating with an LLM to create a fleshed out diagram prompt can be effective. Ask it to list out entities including attributes and constraints. Then ask it to list out relationships between entities including cardinality.
Example diagrams
ERDs vs. database diagrams
- ERDs are often database diagrams, representing the data model or data schema that is stored in a RDBMS (relational database management system).