" ProgrammingError:列" genre_id"关系"music_album"不存在"虽然该列确实存在 [英] "ProgrammingError: column "genre_id" of relation "music_album" does not exist" while the column does exist

查看:99
本文介绍了" ProgrammingError:列" genre_id"关系"music_album"不存在"虽然该列确实存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下型号:

class CulturalDocument(CacheMixin, models.Model):
    ...
    uuid = UUIDField(unique=True)


class Genre(CulturalDocument):
    name = models.CharField(max_length=32)
    ...

class Album(CulturalDocument):
    ...
    genre = models.ForeignKey(Genre, null=True, blank=True)

我在genre属性中添加了向南迁移.

I added the genre attribute with a south migration.

我可以使用pg_admin在表music_album中看到列genre_id.

I can see the column genre_id in the table music_album using pg_admin.

但是,当我这样做时:

    album = Album.objects.create(uuid=3,
                                 release_date=datetime(2000, 1, 1),
                                 title="Fantastic Album",
                                 right_holder=rh)

我明白了:

 "ProgrammingError: column "genre_id" of relation "music_album" does not exist" while the column does exist
 LINE 1: ..._id", "title", "release_date", "right_holder_id", "genre_id"...
 .                                                            ^

在Ubuntu 12.04中使用PostGres 9.2和Django 1.6.

Using PostGres 9.2 and Django 1.6 in Ubuntu 12.04.

生成的SQL是:

INSERT INTO "music_album" ("culturaldocument_ptr_id", "title", "release_date", "right_holder_id", "genre_id") VALUES (%s, %s, %s, %s, %s)

推荐答案

找到了!

运行单元测试时出现此错误.迁移时,我在常规数据库上应用了迁移,但是单元测试使用其他数据库.

I got this error running unit tests. When I migrated, I applied migrations on my regular db, but unit tests use a different db.

我的测试工具Py.test设置为刷新表,但在测试之间不删除它们,以提高速度.因此,测试表使用的是迁移之前现有的方案.我只是删除了它们,并强迫py.test重新创建它们.

Py.test, my test tools, was setup to flush tables, but not delete them between tests, for speed up. Therefor the test tables were using the scheme existing before the migration. I just deleted them and force py.test to recreate them.

这篇关于" ProgrammingError:列" genre_id"关系"music_album"不存在"虽然该列确实存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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