我将此代码写在新文件中,我想运行它。怎么做?我阅读并遵循了文档,但并不太了解...。
def forwards_func(apps, schema_editor):
product = apps.get_model("landings", "Product")
merchant = apps.get_model("landings", "Merchant")
partner = apps.get_model("landings", "Partner")
operator = apps.get_model("landings", "Operator")
db_alias = schema_editor.connection.alias
partner = partner.objects.using(db_alias).filter(name="binding")
merchant = merchant.objects.using(db_alias).filter(name="dc")
operator = operator.objects.using(db_alias).bulk_create([
operator(name="megafon")
])
product.objects.using(db_alias).bulk_create([
product(name="mirrorcheck", merchant=merchant,
mnp_service_name_card="tg_247_mirrorcheck_refund",
partner=partner,
operator=operator,
has_many_subs=True, category='retail',
definition={"sms": {
"text": ""
])
def reverse_func(apps, schema_editor):
operator = apps.get_model("landings", "Operator")
product = apps.get_model("landings", "Product")
db_alias = schema_editor.connection.alias
operator.objects.using(db_alias).filter(name="megafon")
product.objects.using(db_alias).filter(name="mirrorcheck", operator=operator).delete()
operator.delete()
class Migration(migrations.Migration):
dependencies = []
operations = [
migrations.RunPython(forwards_func, reverse_func),
]
答案 0 :(得分:0)
您需要使用以下命令运行该迁移:
./manage.py migrate app_name 0001_migration_name