I developped a website which runs fine on my local machine. I uploaded my site and the Postgres database to Heroku. It displayed correctly, and I'm able to access to the admin console. In the front page of my site I have links that make request to my database, but I receive "relation "mytable" does not exist"
I'm able to make request manually with heroku pg:psql without any problems.
My models are like this :
class Data(models.Model):
i = models.AutoField(primary_key=True)
version = models.CharField(max_length=10, blank=True, null=True)
id = models.JSONField(blank=True, null=True)
attributes = models.JSONField(blank=True, null=True)
audiofiles = models.JSONField(blank=True, null=True)
class Meta:
managed = False
db_table = 'data'
On my settings.py I have the following for Database node (I replaced infos for obvious reasons):
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'dbname',
'USER': 'dbuser',
'PASSWORD': 'dbpassword',
'HOST': '',
'PORT': '5432',
'OPTIONS': {
'options': '-c search_path=card'
}
}
}
db_from_env = dj_database_url.config()
DATABASES['default'].update(db_from_env)
Here my requirements.txt:
asgiref==3.3.1
dj-database-url==0.5.0
Django==3.1.7
django-heroku==0.3.1
gunicorn==20.1.0
psycopg2==2.8.6
pytz==2021.1
sqlparse==0.4.1
whitenoise==5.2.0
I tryed many things like :
- heroku run python manage.py makemigrations followed by migrate
- heroku run python manage.py migrate --run-syncdb
- Drop my database a recreate it
- makemigrations on local then commit the change to heroku (and migrate again on heroku)
If I connect to heroku pg:psql, I can make requests just like my app did, for example SELECT * FROM mytable WHERE i = 1250;
Finally, I guess all prerequisites for heroku are satisfied, because I'm able to upload my site, and its welcome page is displayed properly.
Thousands of thanks if someone can help me :)