Skip to content

SQLTy vs Django ORM

The Django ORM covers most queries in a Django project. The rest, such as reports, window functions, bulk updates and CTEs, often become raw SQL through connection.cursor(), where nothing checks them. SQLTy checks that raw SQL against your schema and types its rows. SQLTy's types are compared with Django's for 102 fields and expressions on PostgreSQL, MySQL and SQLite, and the report is regenerated weekly.

Quick comparison

Django ORM 6.1 SQLTy 0.10
You write Model querysets SQL strings
Types Model fields; querysets are typed through django-stubs Inferred from CREATE TABLE and casts
Raw SQL (cursor.execute, raw()) Unchecked, untyped tuples Checked and typed
Schema Generated from models by migrations Read from a schema dump
Parameters %s on every backend Typed from where they sit; Django's cursor.execute calls aren't checked yet

Where SQLTy is stronger

  • Raw SQL is checked. A misspelled column in cursor.execute is caught before it runs.
  • Types for tuples that cursor.fetchall() returns.
  • SQL that querysets can't express, with the same safety.

Where the Django ORM is stronger

  • Everything it can express, with models, relations, the admin and migrations generated for you.
  • Database portability from one queryset.

Which should you choose?

Keep the ORM. Add SQLTy for the raw SQL your project already has.

What SQLTy is missing

  • Reading Django migrations directly. SQLTy needs SQL DDL, such as a pg_dump --schema-only or the output of sqlmigrate, which needs a database connection.
  • Parameter checks on Django's cursor.execute calls.
  • Typing of Model.objects.raw() results.

Common questions

Can SQLTy read Django migrations?

Not directly. It needs SQL DDL, such as a pg_dump --schema-only or the output of sqlmigrate.

Sources

  • Django 6.1.3 (2026-12-01); scripts/compat/reports/django.md in the SQLTy repository: 81 match, 19 differ, 2 SQLTy gaps
  • Execute raw SQL: Django