#24424: Migrating an 'empty' model with SQLite gives an SQL syntax error
------------------------------------+--------------------------------------
Reporter: adnam | Owner: adnam
Type: Bug | Status: assigned
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: sqlite3 migrations | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+--------------------------------------
Description changed by adnam:
Old description:
> 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.
New description:
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
}}}
}}}
--
--
Ticket URL: <https://code.djangoproject.com/ticket/24424#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/063.9e1256c057c68f4e4728b181164fe7ad%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.