Django在PyCharm中进行移民

时间:2015-08-11 21:04:07

标签: python django pycharm typeerror makemigrations

当我向模型添加没有默认值的新字段时

some_field = models.IntegerField()

并运行makemigrations我收到此消息

`You are trying to add a non-nullable field 'some_field' to sometable without a default; we can't do that (the database needs something to populate existing rows).
Please select a fix:
 1) Provide a one-off default now (will be set on all existing rows)
 2) Quit, and let me add a default in models.py
Select an option: ` 

当我在普通控制台中选择第一个选项时,它设置默认值并正常工作,但是当我在pycharm manage.py控制台中执行相同操作时出现此错误

Traceback (most recent call last):


File "/opt/pycharm-4.5.2/helpers/pycharm/django_manage.py", line 41, in <module>
    run_module(manage_file, None, '__main__', True)
  File "/usr/lib/python2.7/runpy.py", line 176, in run_module
    fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 82, in _run_module_code
    mod_name, mod_fname, mod_loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/dima/Python/nflstats/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/dima/envs/nflstats_env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/home/dima/envs/nflstats_env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/dima/envs/nflstats_env/local/lib/python2.7/site-packages/django/core/management/base.py", line 393, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/dima/envs/nflstats_env/local/lib/python2.7/site-packages/django/core/management/base.py", line 444, in execute
    output = self.handle(*args, **options)
  File "/home/dima/envs/nflstats_env/local/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 125, in handle
    migration_name=self.migration_name,
  File "/home/dima/envs/nflstats_env/local/lib/python2.7/site-packages/django/db/migrations/autodetector.py", line 43, in changes
    changes = self._detect_changes(convert_apps, graph)
  File "/home/dima/envs/nflstats_env/local/lib/python2.7/site-packages/django/db/migrations/autodetector.py", line 185, in _detect_changes
    self.generate_added_fields()
  File "/home/dima/envs/nflstats_env/local/lib/python2.7/site-packages/django/db/migrations/autodetector.py", line 763, in generate_added_fields
    self._generate_added_field(app_label, model_name, field_name)
  File "/home/dima/envs/nflstats_env/local/lib/python2.7/site-packages/django/db/migrations/autodetector.py", line 793, in _generate_added_field
    field.default = self.questioner.ask_not_null_addition(field_name, model_name)
  File "/home/dima/envs/nflstats_env/local/lib/python2.7/site-packages/django/db/migrations/questioner.py", line 137, in ask_not_null_addition
    return self._ask_default()
  File "/home/dima/envs/nflstats_env/local/lib/python2.7/site-packages/django/db/migrations/questioner.py", line 111, in _ask_default
    code = input(">>> ").decode(sys.stdin.encoding)
TypeError: decode() argument 1 must be string, not None

我不明白,我做错了什么?为什么它不在pycharm工作?我怎样才能解决这个问题? 我使用PyCharm 4.5.2 Pro

1 个答案:

答案 0 :(得分:0)

我可以确认这是一个错误。自从4.0.0以来,我一直在Windows 10和Mac OS X Mavericks上遇到这个问题。

我在加载Virtualenv之后保持终端打开并从那里运行命令。