web-dev-qa-db-ja.com

取得の問題Django HerokuでSouthを使用してセットアップ-ProgrammingErrorを取得し続ける:関係が存在しません

これは私がやってきたことです:

ローカル-新しいpostgresデータベースと、2つの異なるアプリからの2つのmodels.pyファイルがあります。

python manage.py syncdb
python manage.py schemamigration api --initial
python manage.py schemamigration extapi --initial
python manage.py migrate api 0001 --fake
python manage.py migrate extapi 0001 --fake

これはうまく機能し、データベースに問題なく追加できます。

次に、空のアプリを作成したHerokuにプッシュすると、次のようになります。

git add .
git commit -m "Ready to go to Heroku"
git Push heroku master
heroku run python manage.py syncdb

これを出力します:

Running `python manage.py syncdb` attached to terminal... up, run.9548
Syncing...
Creating tables ...
Creating table Django_admin_log
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table Django_content_type
Creating table Django_session
Creating table south_migrationhistory

# create superuser Prompt...
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)

Synced:
 > Django.contrib.admin
 > Django.contrib.auth
 > Django.contrib.contenttypes
 > Django.contrib.sessions
 > Django.contrib.messages
 > Django.contrib.staticfiles
 > south
 > rest_framework

Not synced (use migrations):
 - api
 - extapi

次に、これらのアプリをheroku run python manage.py migrateで移行しようとすると、次のエラーが発生します。

Running `python manage.py migrate` attached to terminal... up, run.3724
Running migrations for api:
 - Migrating forwards to 0001_initial.
 > api:0001_initial
FATAL ERROR - The following SQL query failed: ALTER TABLE "api_song" ADD CONSTRAINT "summary_id_refs_id_36bb6e06" FOREIGN KEY ("summary_id") REFERENCES "extapi_summary" ("id") DEFERRABLE INITIALLY DEFERRED;
The error was: relation "extapi_summary" does not exist

Error in migration: api:0001_initial
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/app/.heroku/python/lib/python2.7/site-packages/Django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/app/.heroku/python/lib/python2.7/site-packages/Django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/app/.heroku/python/lib/python2.7/site-packages/Django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/app/.heroku/python/lib/python2.7/site-packages/Django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "/app/.heroku/python/lib/python2.7/site-packages/south/management/commands/migrate.py", line 111, in handle
    ignore_ghosts = ignore_ghosts,
  File "/app/.heroku/python/lib/python2.7/site-packages/south/migration/__init__.py", line 220, in migrate_app
    success = migrator.migrate_many(target, workplan, database)
  File "/app/.heroku/python/lib/python2.7/site-packages/south/migration/migrators.py", line 254, in migrate_many
    result = migrator.__class__.migrate_many(migrator, target, migrations, database)
  File "/app/.heroku/python/lib/python2.7/site-packages/south/migration/migrators.py", line 329, in migrate_many
    result = self.migrate(migration, database)
  File "/app/.heroku/python/lib/python2.7/site-packages/south/migration/migrators.py", line 133, in migrate
    result = self.run(migration, database)
  File "/app/.heroku/python/lib/python2.7/site-packages/south/migration/migrators.py", line 114, in run
    return self.run_migration(migration, database)
  File "/app/.heroku/python/lib/python2.7/site-packages/south/migration/migrators.py", line 85, in run_migration
    south.db.db.execute_deferred_sql()
  File "/app/.heroku/python/lib/python2.7/site-packages/south/db/generic.py", line 318, in execute_deferred_sql
    self.execute(sql)
  File "/app/.heroku/python/lib/python2.7/site-packages/south/db/generic.py", line 282, in execute
    cursor.execute(sql, params)
  File "/app/.heroku/python/lib/python2.7/site-packages/Django/db/backends/util.py", line 53, in execute
    return self.cursor.execute(sql, params)
  File "/app/.heroku/python/lib/python2.7/site-packages/Django/db/utils.py", line 99, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/app/.heroku/python/lib/python2.7/site-packages/Django/db/backends/util.py", line 53, in execute
    return self.cursor.execute(sql, params)
Django.db.utils.ProgrammingError: relation "extapi_summary" does not exist

私には、テーブルが作成されていないように見えますが、なぜそうなのかわかりません。 heroku run python manage.py sqlallを実行すると、すべてが作成されたと表示されますが、データベース自体(herokuがs3で作成したもの)を見ると、app_oneとapp_twoからは何もありません。繰り返しになりますが、これはすべてローカルで完全に機能します。物事が崩壊するのは、herokuが上がるときです。

14
Andrew Konoff

Api_userprofileの作成を延期するだけで処理されるべき循環インポートがありますが、Southがトランザクションを処理する方法のために、それは壊れます。

そう!これを機能させる最も簡単な方法は、syncdbを取得してすべてのテーブルを作成し、移行を偽造することです。

python manage.py syncdb --all

それは私たちを得る:

Synced:
 > Django.contrib.admin
 > Django.contrib.auth
 > Django.contrib.contenttypes
 > Django.contrib.sessions
 > Django.contrib.messages
 > Django.contrib.staticfiles
 > api
 > extapi
 > moodranker
 > recommender
 > south
 > rest_framework

Not synced (use migrations):
 - 

次に、移行を偽造します。

python manage.py migrate --fake
21
Andrew Konoff

移行フォルダを削除してから、

python manage.py makemigrations appname

python manage.py migrate --run-syncdb

python manage.py migrate --fake appname
0
Shinto Joseph