我在我的应用程序中使用网站应用程序(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'