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.")
评论列表
文章目录