Aaron Toliver
Aaron Toliver

Reputation: 195

Heroku Django Database Error

So this is my first Python project and I'm trying to deploy it to Heroku. I've taken a look at quite a few questions regarding this, and I haven't found a solution regarding my exact problem. I'm receiving the following error.

Exception Type:   ProgrammingError
Exception Value:  relation "articles_cover" does not exist
  LINE 1: ..."profession", "articles_cover"."description" FROM "articles_...

I suspect this has something to do with how I've handled the views and models within the file structure. My models are inside the app, and the app is within the overall project folder, and I'm attempting to give certain views outside of the app access to the models. This works perfectly fine locally. Here's the structure.

├───articles
│   ├───migrations
│   │   └───__pycache__
│   ├───templates
│   │   └───articles(<==template tags applies to various elements in files)
│   |───__pycache__
|   |____models.py (<==models here)
├───assets
├───MyProject
│   |───__pycache__
|   |___views.py (<==models applied here)
├───media
└───templates (<==template tags applied to various elements in files)

So I was thinking it was a reference issue having to do with importing the models to views.py. Once again the following seems to work locally, and after looking all over Django's documentation I haven't found another way to do the following.

views.py

from django.http import HttpResponse
from django.shortcuts import render
from articles.models import Article, Cover, Novel, Event, Podcast, Novella, Short

def homepage(request):
    covers = Cover.objects.all()
    novels = Novel.objects.all()
    events = Event.objects.all()
    novellas = Novella.objects.all()
    shorts = Short.objects.all()

    return render(request, 'homepage.html', {
        'covers': covers, 'novels': novels, 'events': events,
        'novellas': novellas, 'shorts': shorts})

def podcast(request):
    podcasts = Podcast.objects.all()
    return render(request, 'podcast.html', {'podcasts': podcasts})

I figure there's something I'm missing when attempting to deploy it to Heroku. I followed the instructions here to the letter, so I'm not sure what to do next.

I know that SQlite, which Django uses, can be a bit iffy in certain situations. Do I need to use something else? If so, what? Is it simply an import issue? Thanks in advance.

UPDATE: I followed everyone's advice and found the Posgress documentation. I installed it via pipenv and added the following lines to my settings.py file.

db_from_env = dj_database_url.config()
DATABASES['default'].update(db_from_env)

I've tried different ways of integrating this into the syntax of the original DATABASES variable, but they all produce the same result. "Application Error". When I check the log I find the following.

NameError: name 'DATABASES' is not defined

I feel like I'm missing a step that both Heroku and Django documentation just assume I've already done. I'm just trying to figure out what it is.

ANSWER: Found a great resource Here. Followed it step by step and solved the problem. Thanks to those who answered. You guys led me in the right direction. I'd still be struggling with this otherwise.

Upvotes: 0

Views: 1480

Answers (2)

Priyam Mohanty
Priyam Mohanty

Reputation: 502

When deploying to production on Heroku, it is recommended to use PostgresSQL. It's fairly simple to set up Postgres on Heroku, and connect it to your Django application

Heroku has some great documentation on how to get your application + database up and running.

https://devcenter.heroku.com/articles/django-app-configuration

Upvotes: 1

Daniel Roseman
Daniel Roseman

Reputation: 599580

You cannot run sqlite on Heroku. An sqlite db is a file on the filesystem, which is therefore not shared across dynos and doesn't persist across restarts. Migrations won't work because they will always happen in a separate process, therefore on a separate copy of the db file.

Use a proper database add-on, ie Postgres.

Upvotes: 2

Related Questions