【发布时间】:2019-08-27 01:10:24
【问题描述】:
我的一个迁移具有使用RunPython 运行的附加功能。此消息的目的只是向用户显示一个快乐的消息。唯一的问题是,我需要显示一个应用程序名称,当前迁移是在其中创建和运行的。这有点可能吗?
我的代码:
from django.db import migrations, models
import django.db.models.deletion
def happy_message(apps, schema_editor):
print('A happy message from migration inside app named {}')
class Migration(migrations.Migration):
operations = [
migrations.AddField(
model_name='mymodel',
name='rank_no',
field=models.IntegerField(null=True),
),
migrations.RunPython(
happy_message,
migrations.RunPython.noop
),
]
【问题讨论】:
-
您可以使用--name 标志选项命名您正在迁移