# django-migrate-sql-deux

**URL:** <https://forum.djangoproject.com/t/django-migrate-sql-deux/43071>\
**Category:** Show & Tell\
**Created:** [October 4, 2025, 10:25am UTC](https://forum.djangoproject.com/t/django-migrate-sql-deux/43071 "2025-10-04T10:25:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![browniebroke](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/browniebroke/32/2506_2.png) [@browniebroke](https://forum.djangoproject.com/u/browniebroke)\
**Post date:** [October 4, 2025, 10:25am UTC](https://forum.djangoproject.com/t/django-migrate-sql-deux/43071/1 "2025-10-04T10:25:05Z")

</div>

Ever wanted to have Django migrations help you managed SQL functions and other entities? Introducing django-migrate-sql-deux, if you have this problem, give it a spin!

> **[GitHub - browniebroke/django-migrate-sql-deux: Django Migrations for raw SQL](https://github.com/browniebroke/django-migrate-sql-deux)**
>
> Django Migrations for raw SQL

I encountered this problem a while back, and found Bogdan Klichuk’s django-migrate-sql package, which worked well at the time, but looked no longer maintained. However, as Django evolved, the package needed some tweaks to keep up to date, so I resolved to fork it.

It’s now up to date to the current supported versions of Django 4.2-5.2 and Python 3.10-3.14 (Python 3.9 support was just dropped).

PS: Thanks @jacobtylerwalls for the Django Chat mention which prompted me to promote it a bit more here.

---

<div class="post-metadata">

**Author:** ![CodenameTim](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/codenametim/32/31507_2.png) [@CodenameTim](https://forum.djangoproject.com/u/CodenameTim)\
**Post date:** [October 5, 2025, 1:43pm UTC](https://forum.djangoproject.com/t/django-migrate-sql-deux/43071/2 "2025-10-05T13:43:20Z")

</div>

Oooh very cool. Thanks for mentioning it!

---

<div class="post-metadata">

**Author:** ![adamchainz](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/adamchainz/32/26_2.png) [@adamchainz](https://forum.djangoproject.com/u/adamchainz)\
**Post date:** [October 5, 2025, 11:15pm UTC](https://forum.djangoproject.com/t/django-migrate-sql-deux/43071/3 "2025-10-05T23:15:03Z")

</div>

This is a cool idea, and similar to what I’ve built in the past for views. Good work reviving it!

One small suggestion for improvement: run `textwrap.dedent()` on SQL strings by default, so `SQLItem`s can use natural indentation:

```auto
SQLItem(
    "make_sum",
    """
    create or replace function make_sum(a int, b int) returns int as $$
      begin return a + b;
      end;
    $$ language plpgsql;
    """,
    reverse_sql="""
        drop function make_sum(int, int);
    """
)

```
