Skip to main content

Migrations Plus provides a method to run raw SQL in Django migrations with multiple DB connections.

Install

Using pip:

$ pip install django-migrations-plus

API

RunSQL(sql, reverse_sql=None, state_operations=None, db='default')

Allows running of arbitrary SQL on the database - useful for more advanced features of database backends that Django doesn’t support directly, like partial indexes.

sql, and reverse_sql if provided, should be strings of SQL to run on the database. On most database backends (all but PostgreSQL), Django will split the SQL into individual statements prior to executing them. This requires installing the sqlparse Python library.

The state_operations argument is so you can supply operations that are equivalent to the SQL in terms of project state; for example, if you are manually creating a column, you should pass in a list containing an AddField operation here so that the autodetector still has an up-to-date state of the model (otherwise, when you next run makemigrations, it won’t see any operation that adds that field and so will try to run it again).

db should be a string with the name of the connection from your settings you want to run your SQL on.

Example

from django.db import migrations
import migrations_plus


class Migration(migrations.Migration):

    operations = [
        migrations_plus.RunSQL('DROP TABLE Students;')  # Runs only against connection 'default'
        migrations_plus.RunSQL('DROP TABLE OtherStudents;', db='other')  # Runs only against connection 'other'
    ]

Release files for django-migrations-plus 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-migrations-plus 0.1.1
File Size Uploaded
django-migrations-plus-0.1.1.tar.gz 5.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-migrations-plus 0.1.1
File Interpreter ABI Platform
django_migrations_plus-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 11.9 kB

Release files / django-migrations-plus-0.1.1.tar.gz

Download URL django-migrations-plus-0.1.1.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e0167c8e8cc71dbf6582a423fe793e935d19080b57be74f32d039c94f638099a
BLAKE2b-256 checksum
How to use checksums
265852167f1bbfc3e37a24513ac7c214269a3c40f9b27c0bd49d8bd4b9b27a1d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / django_migrations_plus-0.1.1-py3-none-any.whl

Download URL django_migrations_plus-0.1.1-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ad1d12d50007646e9e7915e3b4659df0eb54bc425add2aefab556e07175f90b4
BLAKE2b-256 checksum
How to use checksums
decd5def69778e81a5bd35290df524e6380aab062d88ecdc1720380f88048858
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page