﻿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
28120	CharField: if max_length=True (or False): makemigrations generates a migration and migrate fails	Carles Pina Estany	Carles Pina Estany	"If a model has a field like:

{{{
    surname = models.CharField(max_length=True, null=True, blank=True)
}}}

python manage.py makemigrations writes a migration file but python manage.py migrate fails with an error:

{{{
carles@pinux:~/git/django-test/mysite$ python3 manage.py migrate
Operations to perform:
  Apply all migrations: admin, app01, auth, contenttypes, sessions
Running migrations:
  Applying app01.0002_auto_20170424_1440... OK
  Applying app01.0003_auto_20170424_1446...Traceback (most recent call last):
  File ""/home/carles/git/django/django/db/backends/utils.py"", line 60, in execute
    return self.cursor.execute(sql)
  File ""/home/carles/git/django/django/db/backends/sqlite3/base.py"", line 289, in execute
    return Database.Cursor.execute(self, query)
sqlite3.OperationalError: near ""True"": syntax error

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File ""manage.py"", line 15, in <module>
    execute_from_command_line(sys.argv)
  File ""/home/carles/git/django/django/core/management/__init__.py"", line 354, in execute_from_command_line
    utility.execute()
  File ""/home/carles/git/django/django/core/management/__init__.py"", line 348, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File ""/home/carles/git/django/django/core/management/base.py"", line 280, in run_from_argv
    self.execute(*args, **cmd_options)
  File ""/home/carles/git/django/django/core/management/base.py"", line 327, in execute
    output = self.handle(*args, **options)
  File ""/home/carles/git/django/django/core/management/commands/migrate.py"", line 200, in handle
    fake_initial=fake_initial,
  File ""/home/carles/git/django/django/db/migrations/executor.py"", line 113, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File ""/home/carles/git/django/django/db/migrations/executor.py"", line 143, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File ""/home/carles/git/django/django/db/migrations/executor.py"", line 240, in apply_migration
    state = migration.apply(state, schema_editor)
  File ""/home/carles/git/django/django/db/migrations/migration.py"", line 122, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File ""/home/carles/git/django/django/db/migrations/operations/fields.py"", line 210, in database_forwards
    schema_editor.alter_field(from_model, from_field, to_field)
  File ""/home/carles/git/django/django/db/backends/base/schema.py"", line 490, in alter_field
    old_db_params, new_db_params, strict)
  File ""/home/carles/git/django/django/db/backends/sqlite3/schema.py"", line 258, in _alter_field
    self._remake_table(model, alter_field=(old_field, new_field))
  File ""/home/carles/git/django/django/db/backends/sqlite3/schema.py"", line 195, in _remake_table
    self.create_model(temp_model)
  File ""/home/carles/git/django/django/db/backends/base/schema.py"", line 290, in create_model
    self.execute(sql, params or None)
  File ""/home/carles/git/django/django/db/backends/base/schema.py"", line 109, in execute
    cursor.execute(sql, params)
  File ""/home/carles/git/django/django/db/backends/utils.py"", line 77, in execute
    return super().execute(sql, params)
  File ""/home/carles/git/django/django/db/backends/utils.py"", line 62, in execute
    return self.cursor.execute(sql, params)
  File ""/home/carles/git/django/django/db/utils.py"", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback)
  File ""/home/carles/git/django/django/db/backends/utils.py"", line 60, in execute
    return self.cursor.execute(sql)
  File ""/home/carles/git/django/django/db/backends/sqlite3/base.py"", line 289, in execute
    return Database.Cursor.execute(self, query)
django.db.utils.OperationalError: near ""True"": syntax error
}}}"	Bug	closed	Database layer (models, ORM)	dev	Normal	fixed		Дилян Палаузов	Ready for checkin	1	0	0	0	0	0
