﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
25417	Add a system check for an invalid default on a model field	André Avorio	Simon Charette	"Hello,

I'm using Django version 1.8.4 and Python 3.4.3.

I created this field:

{{{
tax_rate = models.DecimalField('tax rate (%)', max_digits=3, decimal_places=2, help_text='VAT rate', blank=True, null=True, default=20.00)
}}}

I then ran `python manage.py migrate` and got the database table created. All good.

I then decided I wanted more digits, so I changed that field to:

{{{
tax_rate = models.DecimalField('tax rate (%)', max_digits=5, decimal_places=2, help_text='VAT rate', blank=True, null=True, default=20.00)
}}}

Now, when I run `python manage.py migrate` I get the following error:

{{{
File ""manage.py"", line 10, in <module>
  execute_from_command_line(sys.argv)
File ""django-project/.venv/lib/python3.4/site-packages/django/core/management/__init__.py"", line 338, in execute_from_command_line
  utility.execute()
File ""django-project/.venv/lib/python3.4/site-packages/django/core/management/__init__.py"", line 330, in execute
  self.fetch_command(subcommand).run_from_argv(self.argv)
File ""django-project/.venv/lib/python3.4/site-packages/django/core/management/base.py"", line 393, in run_from_argv
  self.execute(*args, **cmd_options)
File ""django-project/.venv/lib/python3.4/site-packages/django/core/management/base.py"", line 444, in execute
  output = self.handle(*args, **options)
File ""django-project/.venv/lib/python3.4/site-packages/django/core/management/commands/migrate.py"", line 222, in handle
  executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
File ""django-project/.venv/lib/python3.4/site-packages/django/db/migrations/executor.py"", line 110, in migrate
  self.apply_migration(states[migration], migration, fake=fake, fake_initial=fake_initial)
File ""django-project/.venv/lib/python3.4/site-packages/django/db/migrations/executor.py"", line 148, in apply_migration
  state = migration.apply(state, schema_editor)
File ""django-project/.venv/lib/python3.4/site-packages/django/db/migrations/migration.py"", line 115, in apply
  operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File ""django-project/.venv/lib/python3.4/site-packages/django/db/migrations/operations/fields.py"", line 201, in database_forwards
  schema_editor.alter_field(from_model, from_field, to_field)
File ""django-project/.venv/lib/python3.4/site-packages/django/db/backends/base/schema.py"", line 484, in alter_field
  old_db_params, new_db_params, strict)
File ""django-project/.venv/lib/python3.4/site-packages/django/db/backends/base/schema.py"", line 566, in _alter_field
  old_default = self.effective_default(old_field)
File ""django-project/.venv/lib/python3.4/site-packages/django/db/backends/base/schema.py"", line 211, in effective_default
  default = field.get_db_prep_save(default, self.connection)
File ""django-project/.venv/lib/python3.4/site-packages/django/db/models/fields/__init__.py"", line 1627, in get_db_prep_save
  self.max_digits, self.decimal_places)
File ""django-project/.venv/lib/python3.4/site-packages/django/db/backends/base/operations.py"", line 477, in value_to_db_decimal
  return utils.format_number(value, max_digits, decimal_places)
File ""django-project/.venv/lib/python3.4/site-packages/django/db/backends/utils.py"", line 200, in format_number
  value = value.quantize(decimal.Decimal("".1"") ** decimal_places, context=context)
decimal.InvalidOperation: [<class 'decimal.InvalidOperation'>]
}}}

Is this an actual bug, or am I doing something I shouldn't be?"	New feature	closed	Core (System checks)	dev	Normal	fixed	decimal, InvalidOperation, migrations	Simon Charette	Ready for checkin	1	1	0	1	0	0
