[英]Order of Django Data Migrations
我在应用程序中使用了站点应用程序( django.contrib.sites
)。 我创建了一个数据迁移,该数据迁移在创建数据库时设置当前站点的值,但是我的数据迁移是在安装站点应用程序之前执行的。 在sites
迁移之后,如何强制执行数据迁移。
这个项目原本打算用作其他项目的种子,而且我经常删除数据库并重新启动,所以重要的是,初始makemigrations / migrate命令可以直接使用。
我的迁移文件位于主应用程序文件夹中:
project folder
..+app
....+migrations
......-0001_initial.py
这是迁移文件的内容:
from __future__ import unicode_literals
from django.db import migrations
def set_development_site(apps, schema_editor):
Site = apps.get_model('sites', 'Site')
current= Site.objects.get_current()
current.domain = "localhost:8000"
current.name = "Django-Angular-Webpack-Starter"
current.save()
class Migration(migrations.Migration):
dependencies = [
]
operations = [
migrations.RunPython(set_development_site),
]
以及python manage.py migrate
命令的输出:
Operations to perform:
Apply all migrations: admin, app, auth, authentication, authtoken, contenttypes, sessions, sites
Running migrations:
Applying contenttypes.0001_initial... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0001_initial... OK
Applying authentication.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying app.0001_initial...Traceback (most recent call last):
File "/home/user/devel/django-angular-webpack-starter/venv/lib/python3.5/site-packages/django/apps/registry.py", line 149, in get_app_config
return self.app_configs[app_label]
KeyError: 'sites'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.