e-s*_*tis 4 python django postgresql orm
我有以下型号:
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)
Run Code Online (Sandbox Code Playgroud)
我添加了genre一个南迁移属性.
我可以使用pg_admin 查看genre_id表中的列music_album.
但是,当我这样做时:
album = Album.objects.create(uuid=3,
release_date=datetime(2000, 1, 1),
title="Fantastic Album",
right_holder=rh)
Run Code Online (Sandbox Code Playgroud)
我明白了:
"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"...
. ^
Run Code Online (Sandbox Code Playgroud)
在Ubuntu 12.04中使用PostGres 9.2和Django 1.6.
生成的SQL是:
INSERT INTO "music_album" ("culturaldocument_ptr_id", "title", "release_date", "right_holder_id", "genre_id") VALUES (%s, %s, %s, %s, %s)
Run Code Online (Sandbox Code Playgroud)
找到了 !
运行单元测试时出现此错误.迁移时,我在常规数据库上应用了迁移,但单元测试使用不同的数据库.
Py.test,我的测试工具,设置为刷新表,但不是在测试之间删除它们,以加快速度.因此,测试表使用迁移之前存在的方案.我刚删除它们并强制py.test重新创建它们.
| 归档时间: |
|
| 查看次数: |
3852 次 |
| 最近记录: |