繁体   English   中英

PyCharm中的Django makemigrations

[英]Django makemigrations in PyCharm

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

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM