Django: migrations for tables that are not linked to models

63 views Asked by At

I have a set of tables (mostly some denormilized pre-calculated values storages) that are not linked to any model, I just use raw select queries on them. Is it possible to use any migration frameworks for them (for example, I want to add column and deploy this change to all environments). Thanks.

1

There are 1 answers

0
Kevin Christopher Henry On BEST ANSWER

You can use the usual migrations system.

First, create an empty migration (in whatever app is most appropriate).

python manage.py makemigrations --empty yourappname

Then put in whatever RunSQL operations you need (including the SQL for reverting the changes, if you want).

operations = [
    migrations.RunSQL("CREATE ...",
                      "DROP ..."),
    ...
]

The result can be run right alongside your migrations for Django models.

python manage.py migrate