Search code examples
djangoherokudjango-modelsheroku-postgres

Django migrations not pushing to Heroku


I have updated a Django blog to use slug urls <slug:slug>/ instead of id <int:pk>/. I also added a slugField to the Article model, and converted all hrefs to article.slug. Ran migrations and everything worked fine locally. However, when I pushed to Heroku I got an error.

This is what happens when I attempt to save a new article.


ProgrammingError at /admin/articles/article/
column articles_article.slug does not exist
LINE 1: ...ticles_article"."id", "articles_article"."title", "articles_...
                                                             ^
Request Method: GET
Request URL:    https://***********.herokuapp.com/admin/articles/article/
Django Version: 2.1.4
Exception Type: ProgrammingError
Exception Value:    
column articles_article.slug does not exist
LINE 1: ...ticles_article"."id", "articles_article"."title", "articles_...
                                                             ^

I checked my Heroku Postgress database and I found that the new slug column hadn't been added even though I did migrations. I'm not exactly sure what to do next. I'm currently searching for ways to manually update the heroku postgress, but if there's a less invasive way to solve this problem I'm all ears.


Solution

  • first verify that the migration was executed (heroku)

    verify that the last migration of the article model is in the django_migrations table
    

    In case you can't find it, make sure you have updated migrations (local)

    python manage.py makemigrations
    

    run the migration in db production (heroku)

    heroku run python manage.py migrate