2

When I add new field without default value to my model

some_field = models.IntegerField()

and run makemigrations I get this message

`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: ` 

When I select first option in normal console it set default value and work fine, but when I do the same in pycharm manage.py console I get this error

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

I don't understand, what did I do wrong? Why it don't working in pycharm? How can I fix this? I use PyCharm 4.5.2 Pro

Dima Kudosh
  • 7,126
  • 4
  • 36
  • 46
  • I mean this is not really a big deal just set your integerfield to default=0, it is the same concept as option 1 in the shell. –  Aug 11 '15 at 21:22

1 Answers1

0

I can confirm that this is a bug. I've been having this problem since 4.0.0 on both Windows 10 and Mac OS X Mavericks.

I rather keep a terminal open after loading my Virtualenv and run the commands from there.

Daniel van Flymen
  • 10,931
  • 4
  • 24
  • 39