0

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.

2
  • Have you run manage.py migrate? Did that throw any errors? Because in my experience SQLite does not work well on Heroku (if at all) because you cannot access the file system directly. Commented Aug 9, 2018 at 21:19
  • Yes. I ran it before I deployed to Heroku. No errors. Commented Aug 9, 2018 at 21:30

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

4 Comments

I followed the instructions on how to set up postgresSQL. I'm getting a new error now. "DATABASES['default'].update(db_from_env) NameError: name 'DATABASES' is not defined".
You need a dictionary to represent DATABASES. The NameError stems from there not being a DATABASES variable in your settings.py file. Add DATABASES = { 'default': {'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME':, 'USER':, 'PASSWORD':, 'HOST': localhost, 'PORT'}}
I left fields blank that must be filled out with your database information provided by Heroku.
Thank you, Priyam. Your suggestions led me in the right direction. I found a great resource [link]developer.mozilla.org/en-US/docs/Learn/Server-side/Django/… Went step by step and found sooo many things I was doing wrong it wasn't even funny. But it solved all of my problems. Thanks again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.