django makemigrations在尝试将ForeignKey添加到现有模型时失败

时间:2015-08-20 18:14:18

标签: python django django-models makemigrations

我有一个模型,我正在尝试添加一个foreignkey字段。

这是字段定义:

part_of_speech = models.ForeignKey('PartOfSpeech', help_text=_('Translation | part_of_speech | help_text'), verbose_name = _('Translation','part_of_speech'))

当我尝试执行makemigrations命令时,出现以下错误:

Migrations for 'dictionary':
  0024_translation_part_of_speech.py:
    - Add field part_of_speech to translation
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/user/.virtualenvs/env2/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/Users/user/.virtualenvs/env2/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/user/.virtualenvs/env2/lib/python2.7/site-packages/django/core/management/base.py", line 390, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/user/.virtualenvs/env2/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute
    output = self.handle(*args, **options)
  File "/Users/user/.virtualenvs/env2/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 143, in handle
    self.write_migration_files(changes)
  File "/Users/user/.virtualenvs/env2/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 171, in write_migration_files
    migration_string = writer.as_string()
  File "/Users/user/.virtualenvs/env2/lib/python2.7/site-packages/django/db/migrations/writer.py", line 146, in as_string
    operation_string, operation_imports = OperationWriter(operation).serialize()
  File "/Users/user/.virtualenvs/env2/lib/python2.7/site-packages/django/db/migrations/writer.py", line 104, in serialize
    _write(arg_name, arg_value)
  File "/Users/user/.virtualenvs/env2/lib/python2.7/site-packages/django/db/migrations/writer.py", line 74, in _write
    arg_string, arg_imports = MigrationWriter.serialize(_arg_value)
  File "/Users/user/.virtualenvs/env2/lib/python2.7/site-packages/django/db/migrations/writer.py", line 354, in serialize
    return cls.serialize_deconstructed(path, args, kwargs)
  File "/Users/user/.virtualenvs/env2/lib/python2.7/site-packages/django/db/migrations/writer.py", line 248, in serialize_deconstructed
    arg_string, arg_imports = cls.serialize(arg)
  File "/Users/user/.virtualenvs/env2/lib/python2.7/site-packages/django/db/migrations/writer.py", line 276, in serialize
    value = force_text(value)
  File "/Users/user/.virtualenvs/env2/lib/python2.7/site-packages/django/utils/encoding.py", line 92, in force_text
    s = six.text_type(s)
  File "/Users/user/.virtualenvs/env2/lib/python2.7/site-packages/django/utils/functional.py", line 141, in __text_cast
    return func(*self.__args, **self.__kw)
TypeError: ugettext() takes exactly 1 argument (2 given)

1 个答案:

答案 0 :(得分:1)

帮助文本声明(对ugetttext的调用)格式不正确。要解决此问题,请更改此:

verbose_name = _('Translation','part_of_speech')

到此:

verbose_name = _('Translation | part_of_speech')