[英]Django 1.7 migrations and flush
I have an app that uses initial models (auth.Group). 我有一个使用初始模型(auth.Group)的应用程序。 Prior to django 1.7, I used
Group.objects.get_or_create
in the 'models.py'. 在Django 1.7之前,我在'models.py'中使用了
Group.objects.get_or_create
。 This was ugly but worked most of the time. 这很丑陋,但大部分时间都有效。 Changes to the app loading in django 1.7 broke this.
django 1.7中对应用程序加载的更改打破了这一点。
Now I am trying to use data migrations to provide these groups. 现在,我正在尝试使用数据迁移来提供这些组。 This works the first time
./manage migrate
is run. 这在第一次运行
./manage migrate
时./manage migrate
。 However, when I run ./manage.py flush
the groups are missing. 但是,当我运行
./manage.py flush
这些组丢失了。 Running ./manage migrate
again also does not create them. 再次运行
./manage migrate
也不会创建它们。 What I want is to have this data in place after ./manage flush
. 我想要的是在
./manage flush
之后放置这些数据。
I can see why django acts like this, but is there some way to flag a migration as always needing to be rerun? 我可以看到django为何会这样,但是有某种方法可以将迁移标记为始终需要重新运行吗? Is this some way to have these groups in place always in a clean way.
是否可以通过某种方式使这些组始终保持干净。
我认为post_migrate信号是重新创建组的理想选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.