私は Django==1.7 を使用しており、4 つのアプリケーションがあります。
frontend
game
geo
people
アプリの設定は次のようになります。
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'fandjango',
'people',
'geo',
'game',
'frontend'
)
データベースの設定は次のとおりです。
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'hoods_raising',
'USER': 'hoods_raising',
'PASSWORD': 'hr$nestor$123',
'HOST': 'localhost',
'TEST_CHARSET': 'utf8mb4'
}
}
私のアプリケーションには移行とテストがあります:
game
migrations
0001_initial.py
geo
migrations
0001_initial.py
tests.py
people
migrations
0001_initial.py
0002_install_data.py
問題を絞り込むために、多くのファイルが省略されました (必要に応じて、より多くのファイルを使用して質問を拡張しますmodels.py
) views.py
。
の内容は次の0002_install_data.py
とおりです。
class Migration(migrations.Migration):
dependencies = [
('people', '0001_initial'),
]
operations = [
migrations.RunPython(NamesInstaller(), lambda apps, schema_editor: None)
]
manage.py migrate
データベースをインストールするために実行すると、すべてが期待どおりに機能します。
テストを実行する場合manage.py test
、最初のステップはテスト データベースのインストールです。何か奇妙なことが起こります:
最初に実行される移行は 0002_install_data です。他のテーブルは作成されず (例: auth テーブル、geo テーブル、game テーブル、fandjango テーブルなど)、移行 0001_initialpeople
は実行されません。このような理由で、依存エラーが発生します0002_install_data
(0001_initial
存在しないと表示されます)。KeyError: u"Migration people.0002_install_data dependencies references nonexistent parent node (u'people', u'0001_initial')"
なぜこれが起こっているのでしょうか?test
コマンドがアプリケーションの移行を正しく調整しないのはなぜですか? (これは では発生しませmanage.py migrate
ん)。