Skip to content
Advertisement

Django test error: Column does not exist

Postgresql, Django 2.0, Python 3.6.4

After running a migration that changed the name of a field desktop_pay to simply pay, I’m getting an error when running manage.py test saying the column pay does not exist.

Here’s the migration:

JavaScript

Here’s the error:

JavaScript

If I start a psql prompt, though, I can clearly see that the column does exist, at least in the “real” table.

JavaScript

What’s going on here? Why is Django not finding the column? How can I debug this?

Advertisement

Answer

I’ve run into these ‘column does not exist’ errors when my migrations somehow got messed up, sometimes this has happened when I accidentally deleted/overwrote migrations, but I’ve also had it happen just by running typical migrations which I can’t really explain.

So I would guess you would have to pinpoint the problem in your migrations. What worked for me was, after confirming my schema was in fact as I wanted to be, resetting migrations with the help of Scenario #2 here.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement