问题描述
我在进行迁移时不断收到以下错误(python manage.py migrate):
I keep getting the following error when doing a migration (python manage.py migrate):
django.db.utils.ProgrammingError: column "name" of relation "django_content_type" does not exist
我已经做了以下尝试并修复它,但没有成功:
I've done the following to try and fix it but without success:
- 我已经删除了每个模型的所有迁移文件
- 删除了 django_migrations 中的所有记录
- 运行 python manage.py migrate --fake-initial
运行 Django 1.8.2.
Running Django 1.8.2.
python manage.py showmigrations
admin
[ ] 0001_initial
auth
[ ] 0001_initial
[ ] 0002_alter_permission_name_max_length
[ ] 0003_alter_user_email_max_length
[ ] 0004_alter_user_username_opts
[ ] 0005_alter_user_last_login_null
[ ] 0006_require_contenttypes_0002
contenttypes
[X] 0001_initial
[ ] 0002_remove_content_type_name
hashtags
[ ] 0001_initial
[ ] 0002_hashtagvisit_user
posts
[ ] 0001_initial
[ ] 0002_auto_20150530_0715
sessions
[ ] 0001_initial
users
[ ] 0001_initial
感谢您的帮助.
推荐答案
在升级到 1.8 并从 MySQL 迁移到 Postgres 时遇到这个问题.
Encountered this when upgrading to 1.8 and migrating from MySQL to Postgres.
我无法解释错误发生的原因,但我可以通过手动添加列来绕过它:
I can't explain why the error occurs, but I was able to get around it by manually adding the column:
删除所有迁移
Delete all migrations
从 django_migrations
手动添加name
列:
ALTER TABLE django_content_type ADD COLUMN name character varying(50) NOT NULL DEFAULT 'someName';
运行假初始:$ python manage.py migrate --fake-initial
Edit 12/2016:我建议将此作为一种解决方法,更适合个人项目或本地环境,而不是生产环境.显然,如果您关心自己的迁移历史,这不是正确的做法.
Edit 12/2016: I'm recommending this as a workaround, more suited for personal projects or local environments and not production environments. Obviously if you care about your migration history this is not the way to go.
这篇关于Django 列“名称"关系“django_content_type"不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!