質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Django

DjangoはPythonで書かれた、オープンソースウェブアプリケーションのフレームワークです。複雑なデータベースを扱うウェブサイトを開発する際に必要な労力を減らす為にデザインされました。

Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

PostgreSQL

PostgreSQLはオープンソースのオブジェクトリレーショナルデータベース管理システムです。 Oracle Databaseで使われるPL/SQLを参考に実装されたビルトイン言語で、Windows、 Mac、Linux、UNIX、MSなどいくつものプラットフォームに対応しています。

Q&A

1回答

1872閲覧

dojangをHerokuにアップし、migrateすdjango.db.utils.ProgrammingError: relation "<app-name>" does not exisという

haruu11113

総合スコア23

Django

DjangoはPythonで書かれた、オープンソースウェブアプリケーションのフレームワークです。複雑なデータベースを扱うウェブサイトを開発する際に必要な労力を減らす為にデザインされました。

Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

PostgreSQL

PostgreSQLはオープンソースのオブジェクトリレーショナルデータベース管理システムです。 Oracle Databaseで使われるPL/SQLを参考に実装されたビルトイン言語で、Windows、 Mac、Linux、UNIX、MSなどいくつものプラットフォームに対応しています。

0グッド

0クリップ

投稿2018/11/11 14:28

前提・実現したいこと

herokuにDjangoで作成したWEBアプリをデプロイしたいのですが、'heroku run python manage.py migrate'を行う際にエラーが出ます。ローカルでは出なかったエラーなのでおそらく、ローカルでdjangoのデフォルトで用いられるsqlite3というデータベースをherokuのpostgreSQLに変える際にミスをしたのかと考えています。 models.pyではauthBaseUserを使ってログインなどを実装しようとしています。

実行した事

heroku run python manage.py makemigrations heroku run python manaeg.py migrate auth heroku run python manaeg.py migrate  <ここでエラー

発生している問題・エラーメッセージ

Operations to perform: Apply all migrations: admin, auth, contenttypes, sessions Running migrations: Applying admin.0001_initial...Traceback (most recent call last): File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute return self.cursor.execute(sql, params) psycopg2.ProgrammingError: relation "register_user" does not exist The above exception was the direct cause of the following exception: Traceback (most recent call last): File "manage.py", line 15, in <module> execute_from_command_line(sys.argv) File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line utility.execute() File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv self.execute(*args, **cmd_options) File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute output = self.handle(*args, **options) File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 83, in wrapped res = handle_func(*args, **kwargs) File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 203, in handle fake_initial=fake_initial, File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/executor.py", line 117, in migrate state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial) File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial) File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/executor.py", line 244, in apply_migration state = migration.apply(state, schema_editor) File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 106, in __exit__ self.execute(sql) File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 133, in execute cursor.execute(sql, params) File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 100, in execute return super().execute(sql, params) File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute return self._execute_with_wrappers(sql, params, many=False, executor=self._execute) File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers return executor(sql, params, many, context) File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute return self.cursor.execute(sql, params) File "/app/.heroku/python/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__ raise dj_exc_value.with_traceback(traceback) from exc_value File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute return self.cursor.execute(sql, params) django.db.utils.ProgrammingError: relation "register_user" does not exist

該当のソースコード

project/setting.py

python

1""" 2Django settings for project project. 3 4Generated by 'django-admin startproject' using Django 2.0.4. 5 6For more information on this file, see 7https://docs.djangoproject.com/en/2.0/topics/settings/ 8 9For the full list of settings and their values, see 10https://docs.djangoproject.com/en/2.0/ref/settings/ 11""" 12 13import os 14# for postgraSQL 15# import psycopg2 16# DATABASE_URL = os.environ['DATABASE_URL'] 17# conn = psycopg2.connect(DATABASE_URL, sslmode='require') 18 19import dj_database_url 20DATABASES = { 'default': dj_database_url.config() } 21DATABASES['default'] = dj_database_url.config(conn_max_age=600, ssl_require=True) 22# ------------ 23 24 25# Build paths inside the project like this: os.path.join(BASE_DIR, ...) 26BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 27 28 29# Quick-start development settings - unsuitable for production 30# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ 31 32# SECURITY WARNING: keep the secret key used in production secret! 33SECURITY = '設定してます。' 34 35# SECURITY WARNING: don't run with debug turned on in production! 36DEBUG = True 37 38ALLOWED_HOSTS = [] 39 40 41# Application definition 42 43INSTALLED_APPS = [ 44 'django.contrib.admin', 45 'django.contrib.auth', 46 'django.contrib.contenttypes', 47 'django.contrib.sessions', 48 'django.contrib.messages', 49 'django.contrib.staticfiles', 50 'register.apps.RegisterConfig', 51] 52 53MIDDLEWARE = [ 54 'django.middleware.security.SecurityMiddleware', 55 'django.contrib.sessions.middleware.SessionMiddleware', 56 'whitenoise.middleware.WhiteNoiseMiddleware', 57 'django.middleware.common.CommonMiddleware', 58 'django.middleware.csrf.CsrfViewMiddleware', 59 'django.contrib.auth.middleware.AuthenticationMiddleware', 60 'django.contrib.messages.middleware.MessageMiddleware', 61 'django.middleware.clickjacking.XFrameOptionsMiddleware', 62] 63# for whitenoise 64STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' 65 66 67ROOT_URLCONF = 'project.urls' 68TEMPLATES = [ 69 { 70 'BACKEND': 'django.template.backends.django.DjangoTemplates', 71 'DIRS': [], 72 'APP_DIRS': True, 73 'OPTIONS': { 74 'context_processors': [ 75 'django.template.context_processors.debug', 76 'django.template.context_processors.request', 77 'django.contrib.auth.context_processors.auth', 78 'django.contrib.messages.context_processors.messages', 79 ], 80 }, 81 }, 82] 83 84WSGI_APPLICATION = 'project.wsgi.application' 85 86 87# Database 88# https://docs.djangoproject.com/en/2.0/ref/settings/#databases 89 90# DATABASES = { 91# 'default': { 92# 'ENGINE': 'django.db.backends.sqlite3', 93# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 94# 'CONN_MAX_AGE': 500 95# } 96# } 97 98 99# Password validation 100# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators 101 102AUTH_PASSWORD_VALIDATORS = [ 103 { 104 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 105 }, 106 { 107 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 108 }, 109 { 110 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 111 }, 112 { 113 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 114 }, 115] 116 117 118# Internationalization 119# https://docs.djangoproject.com/en/2.0/topics/i18n/ 120 121LANGUAGE_CODE = 'ja' 122TIME_ZONE = 'Asia/Tokyo' 123USE_I18N = True 124USE_L10N = True 125USE_TZ = True 126 127# staticfiles 128BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 129# Static files (CSS, JavaScript, Images) 130# https://docs.djangoproject.com/en/1.9/howto/static-files/ 131STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') 132STATIC_URL = '/static/' 133# Extra places for collectstatic to find static files. 134STATICFILES_DIRS = ( 135 os.path.join(BASE_DIR, 'static'), 136) 137# ------------- 138 139 140 141# Static files (CSS, JavaScript, Images) 142# https://docs.djangoproject.com/en/2.0/howto/static-files/ 143 144# STATIC_URL = '/static/' 145# カスタムユーザーを使う 146AUTH_USER_MODEL = 'register.User' 147 148# ログインページと、直接ログインページへ行った後のリダイレクトページ 149LOGIN_URL = 'register:login' 150LOGIN_REDIRECT_URL = 'register:top' 151 152# メールをコンソールに表示する 153EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' 154 155

試したこと

先にauth をmigrateするといいという記事を見たのでやってみたのですが、エラーが治りません。

heroku run python manage.py makemigrations heroku run python manaeg.py migrate auth heroku run python manaeg.py migrate  <ここでエラー

補足情報(FW/ツールのバージョンなど)

python 3.6
django 2.1.2
heroku 2018/11/11現在のバージョン

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

パッと見の印象ですが、 Heroku 上で makemigrations を実行するというのは、少し怪しそう(=失敗しやすそう)な感じがしました。 Heroku 上で makemigrations をしてしまうとローカルで成功した migrate と処理の内容・順序が変わってしまう気がするのですが、その点は確証を持ってやられていますか?

もし確証をお持ちでなければ、 Django アプリを Heroku にデプロイする手順についてもう一度お調べになるとよいのではないかと思います(私自身は Heroku に Django アプリをデプロイしたことはありません)。

後は「 Heroku だから失敗するのか」「 postgreSQL だから失敗するのか」「ローカルと違う手順でやっているから失敗するのか」のどれなのかを切り分けて特定されると問題解決が進むものと思います。

まず makemigrations のポイントを解決されて、それでも問題が残るようであればステータスをご共有いただくと何らかお手伝いがさせていただけるものと思います。

投稿2018/11/12 14:16

gh640

総合スコア1407

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問