0

我有一个模型,我正在尝试向它添加一个外键字段。

这是字段定义:

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)
4

1 回答 1

1

帮助文本声明(对 ugetttext 的调用)格式不正确。为了解决这个问题,改变这个:

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

对此:

verbose_name = _('Translation | part_of_speech')
于 2015-08-20T18:24:47.293 回答