私はDjangoとPythonを初めて使用し、チュートリアルに従っていますが、エラーが発生して困惑しています。
djangoモデル/データベースを構築しようとしています。
python manage.py syncdbを実行しようとすると、コマンドラインプロンプトで次のエラーが表示されます。
C:\Users\6233114\Django-Projects\GlobalX>python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
443, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 196,
in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 231,
in execute
self.validate()
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 266,
in validate
num_errors = get_validation_errors(s, app)
File "C:\Python27\lib\site-packages\django\core\management\validation.py", lin
e 30, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "C:\Python27\lib\site-packages\django\db\models\loading.py", line 158, in
get_app_errors
self._populate()
File "C:\Python27\lib\site-packages\django\db\models\loading.py", line 64, in
_populate
self.load_app(app_name, True)
File "C:\Python27\lib\site-packages\django\db\models\loading.py", line 88, in
load_app
models = import_module('.models', app_name)
File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in im
port_module
__import__(name)
File "C:\Users\6233114\Django-Projects\GlobalX\app_data\models.py", line 15, i
n <module>
class LanguageCode(models.Model):
File "C:\Users\6233114\Django-Projects\GlobalX\app_data\models.py", line 27, i
n LanguageCode
languageDirectionID = models.ForeignKey(languageDirection, default=1, db_col
umn="languageDirectionID")
NameError: name 'languageDirection' is not defined
C:\Users\6233114\Django-Projects\GlobalX>
これは私のmodels.pyファイルの縮小版です(1行目から29行目):
from django.db import models
from django.contrib.auth.models import User
class LanguageDirection(models.Model):
languageDirectionID = models.AutoField(primary_key=True, db_column="languageDirectionID")
languageDirectionDescription = models.CharField(max_length=20, db_column="languageDirectionDescription")
languageDirDescription = models.CharField(max_length=20, db_column="languageDirDescription")
textAlign = models.CharField(max_length=20, db_column="textAlign")
oppositeLanguageDirectionDescription = models.CharField(max_length=20, db_column="oppositeLanguageDirectionDescription")
oppositeLanguageDirDescription = models.CharField(max_length=20, db_column="oppositeLanguageDirDescription")
oppositeTextAlign = models.CharField(max_length=20, db_column="oppositeTextAlign")
class Meta:
db_table="languageDirection"
class LanguageCode(models.Model):
languagecodeID = models.AutoField(primary_key=True, db_column="languageCodeID")
languageCodeDescription = models.CharField(max_length=10, db_column="languageCodeDescription")
baseLanguageCode = models.CharField(max_length=10, db_column="baseLanguageCode")
languageNameEng = models.CharField(max_length=255, db_column="languageNameEng")
altLanguageNameEng = models.CharField(max_length=255, blank=True, null=True, db_column="altLanguageNameEng")
languageNameNative = models.CharField(max_length=255, db_column="languageNameNative")
altLanguageNameNative = models.CharField(max_length=255, blank=True, null=True, db_column="altLanguageNameNative")
iso639_1 = models.CharField(max_length=10, blank=True, null=True, db_column="iso639_1")
iso639_2T = models.CharField(max_length=10, db_column="iso639_2T")
iso639_2B = models.CharField(max_length=10, db_column="iso639_2B")
iso639_X = models.CharField(max_length=10, db_column="iso639_X")
languageDirectionID = models.ForeignKey(languageDirection, default=1, db_column="languageDirectionID")
class Meta:
db_table="languageCode"
LanguageDirectionとLangaugeCodeの関係は1対多であり、LanguageDirection.LanguageDirectionID(1)とLanguageCode.LanguageDirectionID(多)です。
このエラーの原因と、これを修正する方法についての提案はありますか?