Django列“名称”关系“ django_content_type”的关系;不存在 [英] Django column "name" of relation "django_content_type" does not exist

查看:164
本文介绍了Django列“名称”关系“ django_content_type”的关系;不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在进行迁移(python manage.py migration)时,我始终收到以下错误:

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:


  1. 我已删除每种模型的所有迁移文件

  2. 删除django_migrations中的所有记录

  3. 运行python manage.py migration --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:


  1. 删除所有迁移

  1. Delete all migrations

django_migrations

手动添加 name 列:

ALTER TABLE django_content_type ADD COLUMN name character varying(50) NOT NULL DEFAULT 'someName';


  • 运行伪造的首字母: $ python manage.py migration- fake-initial

    编辑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”的关系;不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆