SQL to Django ORM Models Converter

Paste any CREATE TABLE SQL and get Django model definitions with the correct field types, ForeignKey, on_delete, Meta class, and indexes.

Runs 100% in your browser. Your input and files never leave your device.

Why use our online SQL to Django ORM Models Converter?

Django models require a specific field class for each SQL type — CharField vs TextField, IntegerField vs BigIntegerField, ForeignKey with on_delete — and a Meta inner class with db_table, unique_together, and indexes. When inheriting a legacy database, translating the DDL to Django models by hand is error-prone. This tool automates the mapping.

How to use SQL to Django ORM Models Converter

  1. 1
    Paste your SQL

    Paste one or more CREATE TABLE statements. Click the Django ORM tab.

  2. 2
    Review the output

    The right panel shows a complete models.py with all model classes, field definitions, and Meta classes.

  3. 3
    Check the type mapping

    Expand the Type Mapping panel to verify every column — SQL type → Django field class.

  4. 4
    Copy or download

    Click Copy to grab models.py, or Download ZIP for the full output.

Frequently Asked Questions

How is the auto-increment primary key handled?

Django automatically adds an integer auto-increment id primary key to every model that does not define one. When your SQL table has an auto-increment integer primary key named id, the converter omits it from the model — Django adds it automatically. For UUID primary keys, the converter emits models.UUIDField(primary_key=True).

How are ForeignKey on_delete actions translated?

ON DELETE CASCADE → models.CASCADE, ON DELETE SET NULL → models.SET_NULL, ON DELETE RESTRICT → models.RESTRICT. If no ON DELETE action is specified, the converter uses models.PROTECT as the safe default.

Are created_at and updated_at columns handled automatically?

Yes, when the "Detect timestamps" option is on. Columns named created_at generate auto_now_add=True and updated_at generate auto_now=True, which is the idiomatic Django pattern.

How are composite unique constraints handled?

Multi-column UNIQUE constraints are rendered as models.UniqueConstraint in the Meta.constraints list, which is the modern Django 2.2+ approach.

What Django version is the output targeting?

Django 5.x. The output uses models.UniqueConstraint and models.Index in the Meta class, which are stable from Django 2.x onwards.

Also useful: Cron BuilderMermaid Live Editor