我正在使用跨站点引用开发Django(1.9)Rest后端和AngularJS前端.尝试执行./manage.py dumpdata
命令时,会抛出以下异常:
$ python manage.py dumpdata -o dev/dumpdata.json CommandError: Unable to serialize database: relation "corsheaders_corsmodel" does not exist LINE 1: SELECT COUNT(*) AS "__count" FROM "corsheaders_corsmodel"
知道如何处理?
我有同样的问题,并通过python manage.py makemigrations
专门为corsheaders
应用程序调用解决它:
$ python manage.py makemigrations corsheaders $ python manage.py migrate
我认为在我的情况下发生的事情是,在从Django 1.8升级到1.9之后,当我更新我的数据库时,从未应用过初始迁移.
我通过注意到corsheaders
应用程序未在Apply all migrations
输出中列出来跟踪它python manage.py migrate
:
$ python manage.py migrate Operations to perform: Apply all migrations: sessions, admin, xyz, auth, contenttypes Running migrations: No migrations to apply.
然而,运行手动迁移corsheaders
实际上会创建初始迁移:
$ python manage.py makemigrations corsheaders Migrations for 'corsheaders': 0001_initial.py: - Create model CorsModel
完成后,migrate
确实会corsheaders
在输出中显示,并按预期成功应用迁移:
$ python manage.py migrate Operations to perform: Apply all migrations: corsheaders, sessions, admin, xyz, auth, contenttypes Running migrations: Rendering model states... DONE Applying corsheaders.0001_initial... OK