"ProgrammingError: column "genre_id" of relation "music_album" does not exist" while the column does exist
django, orm, postgresql, python
Solution
Found it !
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, 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.
Problem
I have the following models : ``` 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) ``` I added the `genre` attribute with a south migration. I can see the column `genre_id` in the table `music_album` using pg_admin. However, when I do this : ``` album = Album.objects.create(uuid=3, release_date=datetime(2000, 1, 1), title="Fantastic Album", right_holder=rh) ``` I get : ``` "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"... . ^ ``` Using PostGres 9.2 and Django 1.6 in Ubuntu 12.04. The generated SQL is : ``` INSERT INTO "music_album" ("culturaldocument_ptr_id", "title", "release_date", "right_holder_id", "genre_id") VALUES (%s, %s, %s, %s, %s) ```