django - 如何在 Django 中存储第三方应用程序迁移

标签 django django-migrations django-scheduler

我对 python 和 django 相当陌生,并试图基于 django-scheduler 包构建一个简单的日历。
根据 django-scheduler 文档,自定义基类可用于添加其他字段、管理器等。

所以,我使用了一个抽象模型来添加一个新字段:

#myproject/customer_calendar/models.py
from django.db import models
from main.models import Customer

class CalendarAbstract(models.Model):
    customer = models.OneToOneField(to=Customer, null=True, blank=True, related_name='calendar')

    class Meta:
        abstract = True

并将其添加到 settings.py
SCHEDULER_BASE_CLASSES = {
    'Calendar': ['customer_calendar.models.CalendarAbstract'],
}

现在,如果我使用 makemigrations 命令,则会在调度程序应用程序(位于当前虚拟环境的站点包中)内创建一个新的迁移,这不允许我通过 VCS 跟踪迁移。

我找到了几个解决方案:

1)将整个调度程序应用程序保留在我的项目中。根据 SO,这被认为是一种不好的做法,应始终通过 pip 检索第三方应用程序。

2) 使用 django 设置将所有 django-scheduler 迁移存储在我的日历应用程序中
MIGRATION_MODULES = {
    'schedule': 'customer_calendar.migrations',
}

第二个对我来说看起来不错,但我不知道它是否被认为是解决这个问题的有效方法。
还有其他方法可以存储第三方应用程序迁移吗?

最佳答案

The second one looks good to me, but I don't know if it's considered to be a valid solution to this problem. Is there any other ways to store third-party apps migrations?



正如 this answer 中所述, FeinCMS docs推荐使用 MIGRATION_MODULES 监控 FeinCMS 作为第三方应用程序的迁移。

FeinCMS itself does not come with any migrations. It is recommended that you add migrations for FeinCMS models yourself inside your project.

...

  • Create a new folder named migrate in your app with an empty init.py inside.

  • Add the following configuration to your settings.py:

    MIGRATION_MODULES = {
         'page': 'yourapp.migrate.page',
         'medialibrary': 'yourapp.migrate.medialibrary', }

You must not use migrations as folder name for the FeinCMS migrations, otherwise Django will get confused.

关于django - 如何在 Django 中存储第三方应用程序迁移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47153776/

相关文章:

django-migrations - Django 1.7 迁移找不到应用程序

django - 在数据迁移中创建自定义权限

python - Elasticbeanstalk/多个数据库的 Django 迁移过程

python - 如何使用 Django-Scheduler 包?

javascript - Django : Files not passed in the request even after setting enctype=multipart/form-data?

python - 使用 markdown2 转换后的 HTML 渲染效果不佳

django - 扩展django rest框架以允许在嵌套序列化程序中继承上下文

python - 尝试在 Windows : AttributeError: 'Settings' object has no attribute 'DATABASES' 上设置 Django 时