My website will just load an existing table (brand) from SQL server and display to index page. I'm able to run the website on my machine without any problem, but it seems like the table doesn't exist when I deploy the project to Heroku.
(The deploy is working normally if the website doesn't connect to the SQL Server.)
These are my settings:
runtime.txt
python-3.7.0
Procfile
web: gunicorn project_heroku.wsgi --log-file -
settings.py
DATABASES = {
'default': {
'ENGINE': 'sql_server.pyodbc',
'NAME': DB_DEFAULT_NAME,
'USER': DB_USER,
'PASSWORD': DB_PASSWORD,
'HOST': DB_HOST,
'PORT': '',
'OPTIONS': {
'driver': 'ODBC Driver 17 for SQL Server',
'unicode_results': True,
}
}
}
models.py
class Brand(models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=60)
class Meta:
managed = False
db_table = 'brand'
views.py
from .models import Brand
def index(request):
brand = list(Brand.objects.all().values())
context = {
'brand': brand
}
return render(request, 'index.html', context)
I added 2 build packs on Heroku
- https://github.com/heroku/heroku-buildpack-apt
- heroku/python
In my Aptfile
unixodbc
unixodbc-dev
python-pyodbc
libsqliteodbc
In my requirements.txt
django
pyodbc
gunicorn
django-heroku
django-pyodbc-azure
The package has been built successfully, but the website give this error
ProgrammingError at /
relation "brand" does not exist
LINE 1: SELECT "brand"."id", "brand"."name" FROM "brand"
Please help! Thanks!!
============================
Update:
I found that Heroku automatically create and attach postgresql which I didn't want. Therefore, I deleted the postgresql and the error is changed to Can't open lib 'ODBC Driver 17 for SQL Server' : file not found. :( I guess that I have to do something with DATABASE_URL config.