How to make migrations for a reusable Django app?

后端 未结 3 1909
我在风中等你
我在风中等你 2021-01-02 04:18

I am making a reusable Django app without a project. This is the directory structure:

/
/myapp/
/myapp/models.py
/myapp/migrations/
/myapp/migrations/__init_         


        
3条回答
  •  盖世英雄少女心
    2021-01-02 04:33

    You need a functional Django project (with your app installed in it) to make migrations.

    A common way to do this is to have a "test" project which contains the bare necessities of a Django project, that you can run to make migrations etc. The migrations will be created in the right place inside your app directory so you can still have proper version control etc within your own reusable app.

    The migrations created in this way will be self-contained (assuming your models don't depend on models from other apps) and can be shipped as part of your packaged, reusable app.

    Many of the larger Django-based projects actually ship a test project as part of their code, so that developers can quickly get it running in order to test apps and make migrations etc.

提交回复
热议问题