ちょっと新しいデータベースを初期化しようとしていますが、マイグレーションを設定する際に問題が発生しています。私が得ているエラーは、私のフォームを設定することによると思われる。私が使っている形で、私はそう選択フィールドを作成しています:メイクマイグレーション実行時のDjangoの関係エラー
PROVINCE_CHOICESはここから来てfrom django import forms
from ..custom_admin import widgets, choices
class MemberForm(forms.Form):
provinces = forms.ChoiceField(label='Provinces', choices=choices.PROVINCE_CHOICES, required=True)
:
from ..base.models import ProvinceCode
PROVINCE_CHOICES = []
for province in ProvinceCode.objects.filter(country_code_id=1).order_by('code'):
PROVINCE_CHOICES.append((province.code, province.code))
問題は、このループは、移行の前に呼び出されていることのようです州モデルが存在しないことを示すエラーが表示されます。このファイルへの参照をコメントアウトすることで、移行は機能しますが、引き続き使用するには実用的ではないようです。このエラーを回避する方法はありますか?
./manage.py makemigrations
Traceback (most recent call last):
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: relation "pc_psr_code" does not exist
LINE 1: ...escription", "pc_psr_code"."country_code_id" FROM "pc_psr_co...
^
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "./manage.py", line 9, in <module>
django.setup()
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/apps/registry.py", line 115, in populate
app_config.ready()
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/debug_toolbar/apps.py", line 15, in ready
dt_settings.patch_all()
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/debug_toolbar/settings.py", line 228, in patch_all
patch_root_urlconf()
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/debug_toolbar/settings.py", line 216, in patch_root_urlconf
reverse('djdt:render_panel')
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/core/urlresolvers.py", line 568, in reverse
app_list = resolver.app_dict[ns]
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/core/urlresolvers.py", line 360, in app_dict
self._populate()
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/core/urlresolvers.py", line 293, in _populate
for pattern in reversed(self.url_patterns):
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/core/urlresolvers.py", line 417, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/core/urlresolvers.py", line 410, in urlconf_module
return import_module(self.urlconf_name)
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 662, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/Users/js/Documents/app/platform/test/pc/urls.py", line 7, in <module>
from .custom_admin import urls as custom_urls
File "/Users/js/Documents/app/platform/test/pc/custom_admin/urls.py", line 3, in <module>
from ..party import views as party_views
File "/Users/js/Documents/app/platform/test/pc/party/views.py", line 1, in <module>
from ..party import forms
File "/Users/js/Documents/app/platform/test/pc/party/forms.py", line 2, in <module>
from ..custom_admin import widgets, choices
File "/Users/js/Documents/app/platform/test/pc/custom_admin/choices.py", line 9, in <module>
for province in ProvinceCode.objects.filter(country_code_id=1).order_by('code'):
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/db/models/query.py", line 258, in __iter__
self._fetch_all()
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/db/models/query.py", line 1074, in _fetch_all
self._result_cache = list(self.iterator())
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/db/models/query.py", line 52, in __iter__
results = compiler.execute_sql()
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 848, in execute_sql
cursor.execute(sql, params)
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/db/utils.py", line 95, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/Users/js/Documents/VirtualEnvironments/pcenv/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "pc_psr_code" does not exist
LINE 1: ...escription", "pc_psr_code"."country_code_id" FROM "pc_psr_co...
省モデル::あなたはアプリレジストリの初期化時にクエリを実行することはできません
class ProvinceCode(models.Model):
code = models.CharField(blank=False, null=False, unique=True)
country_code = models.ForeignKey('CountryCode', blank=False, null=True)
あなたはmakemigrationsを変更しようとしているテーブルに関連したモデルのために特別に、あなたのmodels.pyを表示することができますか? –
モデルを変更しようとしていないので、私は新しいデータベースを初期化しているので、データベースには何も存在しません。しかし私はそのモデルも投稿します – Written
Ok。ここのすべてのベースをカバーするだけで、BaseCodeModelはdjango.dbモデルから継承します。Model right?なぜなら、これがDBの最初の作成であれば、なぜ "FROM"キーワードが作成されるクエリになるのか理解できないからです。それは "テーブルを作成する"コールだけが正しいという理由に立つだろうか? manage.pyが返す小さなスニペットよりも冗長なエラーを出す方法はありますか? –