makemigrations.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:dj-paypal 作者: HearthSim 项目源码 文件源码
def check_migrations():
    from django.db.migrations.autodetector import MigrationAutodetector
    from django.db.migrations.executor import MigrationExecutor
    from django.db.migrations.state import ProjectState

    changed = set()

    print("Checking {} migrations...".format(APP_NAME))
    for db in settings.DATABASES.keys():
        try:
            executor = MigrationExecutor(connections[db])
        except OperationalError as e:
            sys.exit(
                "Unable to check migrations due to database: {}".format(e)
            )

        autodetector = MigrationAutodetector(
            executor.loader.project_state(),
            ProjectState.from_apps(apps),
        )

        changed.update(
            autodetector.changes(graph=executor.loader.graph).keys()
        )

    if changed and APP_NAME in changed:
        sys.exit(
            "A migration file is missing. Please run "
            "`python makemigrations.py` to generate it."
        )
    else:
        print("All migration files present.")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号