3-й день мучаюсь с данной проблемой. На heroku имеется БД MySQL. Также я создал django приложение, которое подключается к данной БД. Если я запускаю его у себя на компьютере, то у меня все работает. Однако если я запущу приложение на heroku, то у меня появляется ошибка:
relation "station" does not exist
LINE 1: ...ongitude", "station"."Type", "station"."Link" FROM "station"
Ощущение будто приложение вообще не видит таблицы БД. Как исправить данную проблему?
Вот полный Traceback:File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/utils.py" in _execute
85. return self.cursor.execute(sql, params)
The above exception (relation "station" does not exist
LINE 1: ...ongitude", "station"."Type", "station"."Link" FROM "station"
^
) was the direct cause of the following exception:
File "/app/.heroku/python/lib/python3.7/site-packages/django/core/handlers/exception.py" in inner
35. response = get_response(request)
File "/app/.heroku/python/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
128. response = self.process_exception_by_middleware(e, request)
File "/app/.heroku/python/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
126. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/app/.heroku/python/lib/python3.7/site-packages/django/views/generic/base.py" in view
69. return self.dispatch(request, *args, **kwargs)
File "/app/.heroku/python/lib/python3.7/site-packages/django/views/generic/base.py" in dispatch
89. return handler(request, *args, **kwargs)
File "/app/task1/views.py" in get
45. for station in stations:
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/models/query.py" in __iter__
272. self._fetch_all()
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/models/query.py" in _fetch_all
1179. self._result_cache = list(self._iterable_class(self))
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/models/query.py" in __iter__
54. results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
1063. cursor.execute(sql, params)
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/utils.py" in execute
100. return super().execute(sql, params)
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/utils.py" in execute
68. return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/utils.py" in _execute_with_wrappers
77. return executor(sql, params, many, context)
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/utils.py" in _execute
85. return self.cursor.execute(sql, params)
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/utils.py" in __exit__
89. raise dj_exc_value.with_traceback(traceback) from exc_value
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/utils.py" in _execute
85. return self.cursor.execute(sql, params)
Exception Type: ProgrammingError at /map/
Exception Value: relation "station" does not exist
LINE 1: ...ongitude", "station"."Type", "station"."Link" FROM "station"
^
settings.pyimport os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '#o032sw#v+_uj&f+a*&n*rz0l@4jyfn%^lub4t=itn%fdaxpni'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'task1',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'geomagnet.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'geomagnet.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'heroku_8165878e13ba965',
'USER': 'be45b00e00ae8e',
'PASSWORD': 'password',
'HOST': 'eu-cdbr-west-02.cleardb.net',
'PORT': '3306',
}
}
# Password validation
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/
LANGUAGE_CODE = 'ru-RU'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
import dj_database_url
db_from_env = dj_database_url.config()
DATABASES['default'].update(db_from_env)
views.py:from django.shortcuts import render
from django.views.generic import TemplateView
from .models import Station, Net, Networkstations
from django.http import HttpResponse
from django.core.serializers.json import DjangoJSONEncoder
import json
class List(TemplateView):
template_name = 'station_list.html'
def get(self, request):
stations = Station.objects.all()
list_name_net = []
stations_out = []
for station in stations:
list_name_net.append(
list(Networkstations.objects.filter(idstation=station.id).values_list('idnet__name', flat=True)))
for station in stations:
stations_out.append(
{'sitecode': station.sitecode, 'name': station.name, 'latitude': station.latitude,
'longitude': station.longitude, 'type': station.type, 'link': station.link, })
ctx = {
'stations': json.dumps(stations_out, cls=DjangoJSONEncoder),
'list_name_net': json.dumps(list_name_net, cls=DjangoJSONEncoder),
}
return render(request, self.template_name, ctx)
procfile:web: gunicorn geomagnet.wsgi --log-file -
.gitignore:__pycache__/
*.pyc
requerements.txt:dj-database-url==0.5.0
Django==2.0
gunicorn==19.9.0
mysqlclient==1.3.13
pytz==2019.1
whitenoise==3.3.1
psycopg2==2.7.3.1
.