You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Getting field metadata for use in autogenerated model diagrams (erdantic) #102
I used the GitHub search to find a similar issue and didn't find it.
I searched the SQLModel documentation, with the integrated search.
I already searched in Google "How to X in SQLModel" and didn't find any information.
I already read and followed all the tutorial in the docs and didn't find an answer.
I already checked if it is not related to SQLModel but to Pydantic.
I already checked if it is not related to SQLModel but to SQLAlchemy.
Commit to Help
I commit to help with one of those options 👆
Example Code
See description
Description
I am trying to add SQLModel support to Erdantic, an entity relationship diagram generator. It supports Pydantic and produces diagrams that look like this:
Wanted Solution
This is hopefully more of a question than a feature request. I would like to know if it is possible to get the metadata that Erdantic needs. You can see instructions and code code showing how this is implemented for Pydantic. It is relatively short. I thought that since SQLModels are Pydantic models I might be able to reuse most of the code, but SQLModel relationship fields appear to be special, and those are crucial.
Wanted Code
The idea is as follows although the way it happens doesn't matter as long as there's a way to do it.
Do you need the Relationship info or would it work if you indeed just 'cast' to pydantic? I think that's possible by using the sqlmodel instances just to provide the data for vanilla pydantic instances, like the from_orm method / factory does.
Hi @DanLipsitt , did you make any progress with this?
I was trying to do the same thing, I looked into generating the ERD based on the underlying sqlalchemy models, but I didn't get that far.
I would also be amazing to render the diagrams inside of mkdocs, on the other hand that would also be possible by using erdantic inside of jupyter and rendering the ipynb with mdocs-jupyter (or something like nbdev).
Anyway, id love to see whether documenting datamodels can be made a little easier :)
Activity
StefanBrand commentedon Mar 15, 2022
Here is the
__dict__of a model instance. Of particular interest in the context of this issue might be__sqlmodel_relationships__.antont commentedon Mar 15, 2022
Do you need the Relationship info or would it work if you indeed just 'cast' to pydantic? I think that's possible by using the sqlmodel instances just to provide the data for vanilla pydantic instances, like the from_orm method / factory does.
DanLipsitt commentedon Mar 23, 2022
@antont Yes, relationship info is important. Otherwise it isn't an entity relationship diagram. 😉
kmcquade commentedon Jun 23, 2022
I just want to say that this would be SO COOL. @DanLipsitt I really hope that you come up with this at some point 😃
hugolytics commentedon Aug 23, 2022
Hi @DanLipsitt , did you make any progress with this?
I was trying to do the same thing, I looked into generating the ERD based on the underlying sqlalchemy models, but I didn't get that far.
I would also be amazing to render the diagrams inside of mkdocs, on the other hand that would also be possible by using erdantic inside of jupyter and rendering the ipynb with mdocs-jupyter (or something like nbdev).
Anyway, id love to see whether documenting datamodels can be made a little easier :)
martin-greentrax commentedon Sep 19, 2022
I would also like to know if you made progress @DanLipsitt :)
austinnottexas commentedon Jan 17, 2023
this would be amazing!
notchatbot commentedon Aug 18, 2023
Are there any news? This would be awesome! What about decomposing the SQLModel into a Dict-ish or into pydantic so erdantic works?
GiorgioSgl commentedon Aug 31, 2023
This would be amazing
zeehio commentedon May 6, 2024
I was able to create an ERD using sqlmodel through a different tool:
npm install -g skeletonand use sqleton:sqleton -L dot -e -o erd.png database.sqlite. This tool creates an ERD from the sqlite schema.(I have no relationship with the sqleton tool so please do your common sense validation checks)
gnthibault commentedon Aug 14, 2025
For those who might end-up here, there's a python module to do the same thing as @zeehio suggested: