def run_migration(self, name, app_label, app_module, save_migration=True):
"""
Run + apply migration to the actual database.
:param name: Name of migration.
:param app_label: App label.
:param app_module: App module path.
:param save_migration: Save migration state?
"""
from .models.migration import Migration
mod = importlib.import_module('{}.migrations.{}'.format(app_module, name))
try:
with self.db.allow_sync():
mod.upgrade(self.migrator)
if save_migration:
Migration.create(
app=app_label,
name=name,
applied=True
)
except Exception as e:
logger.warning('Can\'t migrate {}.migrations.{}: {}'.format(app_module, name, str(e)))
raise
评论列表
文章目录