Bug #72478 mysql-connector-python django inspectdb throws SQL syntax exception
Submitted: 29 Apr 2014 9:00 Modified: 29 May 2014 11:21
Reporter: Marcin Miklaszewski Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / Python Severity:S3 (Non-critical)
Version:1.1.6 OS:Any (Python 3.3)
Assigned to: CPU Architecture:Any
Tags: decimal, inspectdb, python 3.3, syntax

[29 Apr 2014 9:00] Marcin Miklaszewski
Description:
Django manage.py inspectdb throws "django.db.utils.IntegrityError: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use
 near ''decimal' at line 1"

Full traceback:
Traceback (most recent call last):
  File "C:\mm\cbom\cbom\manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Python33\lib\site-packages\django\core\management\__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "C:\Python33\lib\site-packages\django\core\management\__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python33\lib\site-packages\django\core\management\base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "C:\Python33\lib\site-packages\django\core\management\base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "C:\Python33\lib\site-packages\django\core\management\base.py", line 415, in handle
    return self.handle_noargs(**options)
  File "C:\Python33\lib\site-packages\django\core\management\commands\inspectdb.py", line 27, in handle_noargs
    for line in self.handle_inspection(options):
  File "C:\Python33\lib\site-packages\django\core\management\commands\inspectdb.py", line 62, in handle_inspection
    relations = connection.introspection.get_relations(cursor, table_name)
  File "C:\Python33\lib\site-packages\mysql\connector\django\introspection.py", line 96, in get_relations
    my_field_dict = self._name_to_index(cursor, table_name)
  File "C:\Python33\lib\site-packages\mysql\connector\django\introspection.py", line 88, in _name_to_index
    self.get_table_description(cursor, table_name))])
  File "C:\Python33\lib\site-packages\mysql\connector\django\introspection.py", line 65, in get_table_description
    "table_schema = DATABASE() AND data_type='decimal", [table_name])
  File "C:\Python33\lib\site-packages\django\db\backends\util.py", line 69, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "C:\Python33\lib\site-packages\django\db\backends\util.py", line 53, in execute
    return self.cursor.execute(sql, params)
  File "C:\Python33\lib\site-packages\mysql\connector\django\base.py", line 123, in execute
    return self._execute_wrapper(self.cursor.execute, query, args)
  File "C:\Python33\lib\site-packages\mysql\connector\django\base.py", line 109, in _execute_wrapper
    utils.IntegrityError(err.msg), sys.exc_info()[2])
  File "C:\Python33\lib\site-packages\django\utils\six.py", line 535, in reraise
    raise value.with_traceback(tb)
  File "C:\Python33\lib\site-packages\mysql\connector\django\base.py", line 105, in _execute_wrapper
    return method(query, args)
  File "C:\Python33\lib\site-packages\mysql\connector\cursor.py", line 515, in execute
    self._handle_result(self._connection.cmd_query(stmt))
  File "C:\Python33\lib\site-packages\mysql\connector\connection.py", line 636, in cmd_query
    result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
  File "C:\Python33\lib\site-packages\mysql\connector\connection.py", line 554, in _handle_result
    raise errors.get_exception(packet)
django.db.utils.IntegrityError: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use
 near ''decimal' at line 1

How to repeat:
manage.py inspectdb

Suggested fix:
Following the traceback you get to /mysql/connector/django/introspection.py line 65 : 
"table_schema = DATABASE() AND data_type='decimal", [table_name])"
a correction to:
"table_schema = DATABASE() AND data_type='decimal'", [table_name])"
fixes the problem.
[2 May 2014 5:43] Peeyush Gupta
Thank you for the report.

This bug is being fixed in the current development version. Please wait till its uploaded to the downloads web site.
[29 May 2014 11:21] Geert Vanderkelen
Please check again with Connector/Python 1.2.2. If you experience the problem again, please reopen bug #72478 or open new report.
[29 May 2014 22:32] Daniel Honsvick
Thank you Marcin Miklaszewski. Your fix saved me a lot of time.