I'm trying to deploy a simple app (learning log from Python Crash Course) to heroku. The app runs but upon login, I get a 500 error, and in debug=true the error is: no such table: auth_user.
I realise this has something to do with squlite3 and Postgresql, but when I try to build the code in settings:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
the error message is
ImportError: DLL load failed while importing _psycopg: The specified module could not be found.
I have attempted to install and import psycopg2, and it appears to be in requirements.txt.
But I think the paths are not aligning, since psycopg2 is in a python pathway, and setting.py is looking in my project environment.
I'm very confused! Please help!
You have not correctly configured your DATABASES in settings.py. You are attempting to use the default sqlite3 configuration with a PostgreSQL engine which wouldn't work. Also Heroku does not work well with sqlite3 and it wouldn't be a good idea to use it in production. See
Why are my file uploads missing/deleted from the Application?.
It's great you've installed psycopg2 - the database adapter for PostgreSQL. You'd usually have to configure your PostgreSQL database as shown below:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": "mydatabase",
"USER": "mydatabaseuser",
"PASSWORD": "mypassword",
"HOST": "127.0.0.1",
"PORT": "5432",
}
}
Ensure you've created your database and enter the credentials in the DATABASES dictionary in settings.py. When deploying to Heroku, you'd have to provision your database on Heroku by selecting the Postgre addon. Please see Deploying Django App to Heroku: Full Guide for a complete guide to deploying your Django app on Heroku.