﻿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
24424	Removing a model's last field results in SQL syntax error	Adam Hayward	Simon Charette	"'''Edit''': pull-request with fix here https://github.com/django/django/pull/4223

On migrating an empty, abstract model, the method

`django.db.backends.sqlite3.schema.DatabaseSchemaEditor._remake_table()`

tries to execute the following SQL query:

`INSERT INTO ""companies_department__new"" () SELECT  FROM ""companies_department"";`

The correct SQL would be:

`INSERT INTO ""companies_department__new"" SELECT * FROM ""companies_department"";`

This appears to be the same problem specified in this ticket from South: http://south.aeracode.org/ticket/570 (see comment #15 at the bottom).

Will provide the patch to fix this shortly. Any indication of how to create a test case would be appreciated.

The traceback raised is:

{{{
#!div style=""font-size: 80%""
{{{
Traceback (most recent call last):
  File ""manage.py"", line 12, in <module>
    execute_from_command_line(sys.argv)
  File ""/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py"", line 385, in execute_from_command_line
    utility.execute()
  File ""/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py"", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File ""/usr/local/lib/python2.7/site-packages/django/core/management/commands/test.py"", line 50, in run_from_argv
    super(Command, self).run_from_argv(argv)
  File ""/usr/local/lib/python2.7/site-packages/django/core/management/base.py"", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File ""/usr/local/lib/python2.7/site-packages/django/core/management/commands/test.py"", line 71, in execute
    super(Command, self).execute(*args, **options)
  File ""/usr/local/lib/python2.7/site-packages/django/core/management/base.py"", line 338, in execute
    output = self.handle(*args, **options)
  File ""/usr/local/lib/python2.7/site-packages/django/core/management/commands/test.py"", line 88, in handle
    failures = test_runner.run_tests(test_labels)
  File ""/usr/local/lib/python2.7/site-packages/django/test/runner.py"", line 147, in run_tests
    old_config = self.setup_databases()
  File ""/usr/local/lib/python2.7/site-packages/django/test/runner.py"", line 109, in setup_databases
    return setup_databases(self.verbosity, self.interactive, **kwargs)
  File ""/usr/local/lib/python2.7/site-packages/django/test/runner.py"", line 299, in setup_databases
    serialize=connection.settings_dict.get(""TEST"", {}).get(""SERIALIZE"", True),
  File ""/usr/local/lib/python2.7/site-packages/django/db/backends/creation.py"", line 377, in create_test_db
    test_flush=True,
  File ""/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py"", line 115, in call_command
    return klass.execute(*args, **defaults)
  File ""/usr/local/lib/python2.7/site-packages/django/core/management/base.py"", line 338, in execute
    output = self.handle(*args, **options)
  File ""/usr/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py"", line 161, in handle
    executor.migrate(targets, plan, fake=options.get(""fake"", False))
  File ""/usr/local/lib/python2.7/site-packages/django/db/migrations/executor.py"", line 68, in migrate
    self.apply_migration(migration, fake=fake)
  File ""/usr/local/lib/python2.7/site-packages/django/db/migrations/executor.py"", line 102, in apply_migration
    migration.apply(project_state, schema_editor)
  File ""/usr/local/lib/python2.7/site-packages/django/db/migrations/migration.py"", line 108, in apply
    operation.database_forwards(self.app_label, schema_editor, project_state, new_state)
  File ""/usr/local/lib/python2.7/site-packages/django/db/migrations/operations/fields.py"", line 84, in database_forwards
    schema_editor.remove_field(from_model, from_model._meta.get_field_by_name(self.name)[0])
  File ""/usr/local/lib/python2.7/site-packages/django/db/backends/sqlite3/schema.py"", line 196, in remove_field
    self._remake_table(model, delete_fields=[field])
  File ""/usr/local/lib/python2.7/site-packages/django/db/backends/sqlite3/schema.py"", line 145, in _remake_table
    self.quote_name(model._meta.db_table),
  File ""/usr/local/lib/python2.7/site-packages/django/db/backends/schema.py"", line 103, in execute
    cusror.execute(sql, params)
  File ""/usr/local/lib/python2.7/site-packages/django/db/backends/utils.py"", line 65, in execute
    return self.cusror.execute(sql, params)
  File ""/usr/local/lib/python2.7/site-packages/django/db/utils.py"", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File ""/usr/local/lib/python2.7/site-packages/django/db/backends/utils.py"", line 65, in execute
    return self.cusror.execute(sql, params)
  File ""/usr/local/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py"", line 488, in execute
    return Database.Cusror.execute(self, query, params)
django.db.utils.OperationalError: near "")"": syntax error
}}}
}}}"	Bug	closed	Migrations	2.1	Normal	fixed		Markus Holtermann direx Simon Charette	Accepted	1	0	0	0	0	0
