本文整理汇总了Python中south.migration.Migrations.remove方法的典型用法代码示例。如果您正苦于以下问题:Python Migrations.remove方法的具体用法?Python Migrations.remove怎么用?Python Migrations.remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类south.migration.Migrations
的用法示例。
在下文中一共展示了Migrations.remove方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from south.migration import Migrations [as 别名]
# 或者: from south.migration.Migrations import remove [as 别名]
#.........这里部分代码省略.........
for action_name, params in change_source.get_changes():
# Run the correct Action class
try:
action_class = getattr(actions, action_name)
except AttributeError:
raise ValueError(
"Invalid action name from source: %s" % action_name)
else:
action = action_class(**params)
action.add_forwards(forwards_actions)
action.add_backwards(backwards_actions)
print(action.console_line(), file=sys.stderr)
# Nowt happen? That's not good for --auto.
if auto and not forwards_actions:
self.error("Nothing seems to have changed.")
# Work out which apps to freeze
apps_to_freeze = self.calc_frozen_apps(migrations, freeze_list)
# So, what's in this file, then?
file_contents = MIGRATION_TEMPLATE % {
"forwards": "\n".join(forwards_actions or [" pass"]),
"backwards": "\n".join(backwards_actions or [" pass"]),
"frozen_models": freezer.freeze_apps_to_string(apps_to_freeze),
"complete_apps": apps_to_freeze and "complete_apps = [%s]" % (
", ".join(map(repr, apps_to_freeze))) or ""
}
# Custom Bluebottle
# We find and replace the base apps with our mapped models
for model in MODEL_MAP:
model_map = MODEL_MAP[model]
mapping = {
'u"orm[\'{0}\']"'.format(model_map[
'model']): '"orm[\'{0}\']".format(MODEL_MAP[\'{1}\'][\'model\'])'.format(
'{0}', model),
'u\'{0}\''.format(
model_map['table']): 'MODEL_MAP[\'{0}\'][\'table\']'.format(
model),
'u\'{0}\''.format(model_map[
'model_lower']): 'MODEL_MAP[\'{0}\'][\'model_lower\']'.format(
model),
'u\'{0}\''.format(
model_map['app']): 'MODEL_MAP[\'{0}\'][\'app\']'.format(
model),
'[\'{0}\']'.format(
model_map['app']): '[MODEL_MAP[\'{0}\'][\'app\']]'.format(
model),
'to=orm[\'{0}\']'.format(model_map[
'model']): 'to=orm[MODEL_MAP[\'{0}\'][\'model\']]'.format(
model),
'\'object_name\': \'{0}\''.format(model_map[
'class']): '\'object_name\': MODEL_MAP[\'{0}\'][\'class\']'.format(
model)
}
file_contents = reduce(lambda x, y: x.replace(y, mapping[y]),
mapping, file_contents)
# End Custom Bluebottle
# Deal with update mode as late as possible, avoid a rollback as long
# as something else can go wrong.
if update:
last_migration = migrations[-1]
if MigrationHistory.objects.filter(applied__isnull=False,
app_name=app,
migration=last_migration.name()):
print(
"Migration to be updated, %s, is already applied, rolling it back now..." % last_migration.name(),
file=sys.stderr)
migrate_app(migrations, 'current-1', verbosity=verbosity)
for ext in ('py', 'pyc'):
old_filename = "%s.%s" % (
os.path.join(migrations.migrations_dir(),
last_migration.filename), ext)
if os.path.isfile(old_filename):
os.unlink(old_filename)
migrations.remove(last_migration)
# See what filename is next in line. We assume they use numbers.
new_filename = migrations.next_filename(name)
# - is a special name which means 'print to stdout'
if name == "-":
print(file_contents)
# Write the migration file if the name isn't -
else:
fp = open(os.path.join(migrations.migrations_dir(), new_filename),
"w")
fp.write(file_contents)
fp.close()
verb = 'Updated' if update else 'Created'
if empty:
print(
"%s %s. You must now edit this migration and add the code for each direction." % (
verb, new_filename), file=sys.stderr)
else:
print(
"%s %s. You can now apply this migration with: ./manage.py migrate %s" % (
verb, new_filename, app), file=sys.stderr)