Django迁移错误:列不存在 [英] Django Migration Error: Column does not exist

查看:120
本文介绍了Django迁移错误:列不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Python 3,Django 1.8.5,Postgres

Python 3, Django 1.8.5, Postgres

我有一个模型网站,一直工作正常。我最近尝试添加一个字段,机场代码,并迁移数据。

I have a model Sites that has been working fine. I recently tried to add a field, airport_code, and migrate the data.

class Site(BaseModel):

  objects = SiteManager()

  name = models.CharField(max_length=200, unique=True)
  domain = models.CharField(max_length=200, unique=True)
  weather = models.CharField(max_length=10)
  nearby_sites = models.ManyToManyField('self', symmetrical=False, blank=True)
  users = models.ManyToManyField(settings.AUTH_USER_MODEL, blank=True)
  facebook = models.URLField(max_length=200)
  twitter = models.URLField(max_length=200)
  header_override = models.TextField(blank=True)
  email_header_override = models.TextField(blank=True)
  timely_site_tag_id = models.IntegerField()
  timely_featured_tag_id = models.IntegerField()
  timely_domain = models.CharField(max_length=255)
  sitemap_public_id = models.CharField(max_length=255)
  state = models.CharField(max_length=24)
  airport_code = JSONField()

但是,当我运行 makemigrations 我有一个错误:

However, when I ran makemigrations I got an error:

django.db.utils.ProgrammingError:列sites_site.airport_code不存在
LINE 1:。 .._ site。sitemap_public_id,sites_site。state,sites_sit ...

有意义的是,因为当我尝试在迁移期间创建它时,列显然不存在。

Of course, this doesn't make sense, because the column obviously does not exist when I'm trying to create it within the migration.

我已经看到关于堆栈溢出这个错误的许多问题没有得到答复,或者有一个解决方案来手动创建迁移文件,或者销毁和重建数据库。这不是一个好的解决方案。

I have seen many questions about this bug on Stack Overflow that are unanswered, or have a solution to manually create the migration file, or destroy and rebuild the database. This is not an okay solution.

推荐答案

通过在设置中的INSTALLED_APPS中注释出django调试工具栏,这个错误已经解决了。 PY。我不知道为什么调试工具栏是罪魁祸首,但在我评论之后,我能够运行 makemigrations migrate 没有问题。

This bug was resolved for me by commenting out the django debug toolbar from INSTALLED_APPS in settings.py. I am not sure why debug toolbar is the culprit, but after I commented it out, I was able to run makemigrations and migrate with no issue.

希望这有助于某人,因为我花了十二个小时试图弄清楚。

Hoping this helps someone, as I spent twelve hours trying to figure it out.

这篇关于Django迁移错误:列不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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