How do I execute raw SQL in a django migration

前端 未结 2 826
再見小時候
再見小時候 2020-12-30 20:12

I am aware of the cursor object in Django. Is there any other preferred way to execute raw SQL in migrations? I want to introduce postgresql partitioning for one of my model

2条回答
  •  醉酒成梦
    2020-12-30 20:36

    I would recommend django-migrate-sql-deux https://pypi.org/project/django-migrate-sql-deux/

    This way you can manage database objects like views, functions, triggers in declarative way like models in Django. Then you need generate changes into Django migrations through makemigrations. And apply them via migrate. So the development and deploy flow is pretty same.

    It would be awesome if Django would have this system for raw SQL "models" and handle migrations and dependencies automatically in makemigrations and migrate commands like django-migrate-sql-deux.

提交回复
热议问题