Django ORM
Django ORM is supported through PostgreSQL integration. You can use Django's ORM to define your database models and then extract the schema using pg_dump for use with Liam ERD.
Using Django ORM with Liam ERD
- Set up a Django project with PostgreSQL as the database backend:
# settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'your_database_name',
'USER': 'your_database_user',
'PASSWORD': 'your_database_password',
'HOST': 'localhost',
'PORT': '5432',
}
}
- Define your models using Django's ORM:
# models.py
from django.db import models
class Author(models.Model):
name = models.CharField(max_length=100)
email = models.EmailField(unique=True)
def __str__(self):
return self.name
class Post(models.Model):
title = models.CharField(max_length=200)
content = models.TextField()
created_at = models.DateTimeField(auto_now_add=True)
author = models.ForeignKey(Author, on_delete=models.CASCADE, related_name='posts')
def __str__(self):
return self.title
- Apply migrations to create the database schema:
python manage.py makemigrations
python manage.py migrate
- Extract the schema using pg_dump:
pg_dump --schema-only --no-privileges --no-owner --file=schema.sql postgres://username:password@localhost:5432/your_database_name
- Use Liam CLI to build an ER diagram:
npx @liam-hq/cli erd build --format postgres --input schema.sql
Sample Implementation
You can find a sample implementation of Django ORM with Liam ERD on GitHub:
- GitHub Actions: .github/workflows/django-with-postgres.yml
- Django project: samples/django-with-postgres
The sample project demonstrates how to:
- Set up a Django project with PostgreSQL
- Define models using Django's ORM
- Extract the schema using pg_dump
- Use the extracted schema with Liam ERD
Under the Hood
Django ORM generates SQL for PostgreSQL, which is then parsed by Liam ERD using the PostgreSQL parser. For more details about PostgreSQL support, see the PostgreSQL documentation.