Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python manage.py使用mysql数据库迁移时出现SQL查询错误_Python_Mysql_Django - Fatal编程技术网

python manage.py使用mysql数据库迁移时出现SQL查询错误

python manage.py使用mysql数据库迁移时出现SQL查询错误,python,mysql,django,Python,Mysql,Django,我收到SQL错误1064:当我运行python manage.py migrate时,您的SQL语法出现错误。我只是在遵循文档,甚至还没有创建应用程序,忘记编写任何代码吧。我所做的就是根据文档为mysql设置settings.py。这里没有错误,否则我会有一个数据库连接错误 我的设置如下: Windows 8,django 1.8.6,mysqlconnector 2.1.3,也安装了mysqlclient,mysql 5.7.9,Python 3 我已经能够在ubuntu上编写一个完整的应用程

我收到SQL错误
1064:当我运行
python manage.py migrate
时,您的SQL语法出现错误。我只是在遵循文档,甚至还没有创建应用程序,忘记编写任何代码吧。我所做的就是根据文档为mysql设置
settings.py
。这里没有错误,否则我会有一个数据库连接错误

我的设置如下: Windows 8,
django 1.8.6
mysqlconnector 2.1.3
,也安装了
mysqlclient
mysql 5.7.9
Python 3

我已经能够在ubuntu上编写一个完整的应用程序,其中我有
Python2.7

完整的堆栈跟踪如下所示:

django.db.utils.ProgrammingError: (1064 ....)
django.db.utils.ProgrammingError: (1064, "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 '%s' at line 1")
D:\pythonLearn\learningDjango\mysite>python manage.py migrate
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\django\db\backends\utils.py", line 64, in execute return self.cursor.execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\backends\mysql\base.py", line 124, in execute return self.cursor.execute(query, args)
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-md64.egg\MySQLdb\cursors.py", line 207, in execute self.errorhandler(self, exc, value)
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-md64.egg\MySQLdb\connections.py", line 37, in defaulterrorhandler raise errorvalue
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-md64.egg\MySQLdb\cursors.py", line 192, in execute r = self._query(query)
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-md64.egg\MySQLdb\cursors.py", line 356, in _query rowcount = self._do_query(q)
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-md64.egg\MySQLdb\cursors.py", line 320, in _do_query db.query(q)
_mysql_exceptions.ProgrammingError: (1064, "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 '%s' at line 1")

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 354, in execute_from_command_line utility.execute()
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 346, in execute self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 394, in run_from_argv self.execute(*args, **cmd_options)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 445, in execute output = self.handle(*args, **options)
File "C:\Python34\lib\site-packages\django\core\management\commands\migrate.py", line 93, in handle executor = MigrationExecutor(connection, self.migration_progress_callback)
File "C:\Python34\lib\site-packages\django\db\migrations\executor.py", line 19, in __init__self.loader = MigrationLoader(self.connection)
File "C:\Python34\lib\site-packages\django\db\migrations\loader.py", line 47, in __init__self.build_graph()
File "C:\Python34\lib\site-packages\django\db\migrations\loader.py", line 188, in build_graph   self.applied_migrations = recorder.applied_migrations()
File "C:\Python34\lib\site-packages\django\db\migrations\recorder.py", line 59, in applied_migrations self.ensure_schema()
File "C:\Python34\lib\site-packages\django\db\migrations\recorder.py", line 53, in ensure_schema editor.create_model(self.Migration)
File "C:\Python34\lib\site-packages\django\db\backends\base\schema.py", line 289, in create_model self.deferred_sql.extend(self._model_indexes_sql(model))
File "C:\Python34\lib\site-packages\django\db\backends\mysql\schema.py", line 56, in _model_indexes_sql self.connection.cursor(), model._meta.db_table
File "C:\Python34\lib\site-packages\django\db\backends\mysql\introspection.py", line 142, in get_storage_engine
"WHERE table_name = %s", [table_name])
File "C:\Python34\lib\site-packages\django\db\backends\utils.py", line 79, in execute return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\backends\utils.py", line 64, in execute return self.cursor.execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\utils.py", line 98, in __exit__ six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Python34\lib\site-packages\django\utils\six.py", line 658, in reraise raise value.with_traceback(tb)
File "C:\Python34\lib\site-packages\django\db\backends\utils.py", line 64, in execute return self.cursor.execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\backends\mysql\base.py", line 124, in execute return self.cursor.execute(query, args)
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-amd64.egg\MySQLdb\cursors.py", line 207, in execute self.errorhandler(self, exc, value)
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-amd64.egg\MySQLdb\connections.py", line 37, in defaulterrorhandler raise errorvalue
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-amd64.egg\MySQLdb\cursors.py", line 192, in execute r = self._query(query)
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-amd64.egg\MySQLdb\cursors.py", line 356, in _query rowcount = self._do_query(q)
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-amd64.egg\MySQLdb\cursors.py", line 320, in _do_query db.query(q)
django.db.utils.ProgrammingError: (1064, "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 '%s' at line 1")
我已经交叉检查了settings.py文件和所有内容。事实上,连接已经建立,有时它成功地创建了表
django\u content\u type
django\u migrations
,然后给出了这个错误,有时在不创建这些表的情况下,我会得到这个错误

堆栈跟踪打印结束,如下所示:

django.db.utils.ProgrammingError: (1064 ....)
django.db.utils.ProgrammingError: (1064, "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 '%s' at line 1")
D:\pythonLearn\learningDjango\mysite>python manage.py migrate
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\django\db\backends\utils.py", line 64, in execute return self.cursor.execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\backends\mysql\base.py", line 124, in execute return self.cursor.execute(query, args)
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-md64.egg\MySQLdb\cursors.py", line 207, in execute self.errorhandler(self, exc, value)
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-md64.egg\MySQLdb\connections.py", line 37, in defaulterrorhandler raise errorvalue
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-md64.egg\MySQLdb\cursors.py", line 192, in execute r = self._query(query)
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-md64.egg\MySQLdb\cursors.py", line 356, in _query rowcount = self._do_query(q)
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-md64.egg\MySQLdb\cursors.py", line 320, in _do_query db.query(q)
_mysql_exceptions.ProgrammingError: (1064, "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 '%s' at line 1")

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 354, in execute_from_command_line utility.execute()
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 346, in execute self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 394, in run_from_argv self.execute(*args, **cmd_options)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 445, in execute output = self.handle(*args, **options)
File "C:\Python34\lib\site-packages\django\core\management\commands\migrate.py", line 93, in handle executor = MigrationExecutor(connection, self.migration_progress_callback)
File "C:\Python34\lib\site-packages\django\db\migrations\executor.py", line 19, in __init__self.loader = MigrationLoader(self.connection)
File "C:\Python34\lib\site-packages\django\db\migrations\loader.py", line 47, in __init__self.build_graph()
File "C:\Python34\lib\site-packages\django\db\migrations\loader.py", line 188, in build_graph   self.applied_migrations = recorder.applied_migrations()
File "C:\Python34\lib\site-packages\django\db\migrations\recorder.py", line 59, in applied_migrations self.ensure_schema()
File "C:\Python34\lib\site-packages\django\db\migrations\recorder.py", line 53, in ensure_schema editor.create_model(self.Migration)
File "C:\Python34\lib\site-packages\django\db\backends\base\schema.py", line 289, in create_model self.deferred_sql.extend(self._model_indexes_sql(model))
File "C:\Python34\lib\site-packages\django\db\backends\mysql\schema.py", line 56, in _model_indexes_sql self.connection.cursor(), model._meta.db_table
File "C:\Python34\lib\site-packages\django\db\backends\mysql\introspection.py", line 142, in get_storage_engine
"WHERE table_name = %s", [table_name])
File "C:\Python34\lib\site-packages\django\db\backends\utils.py", line 79, in execute return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\backends\utils.py", line 64, in execute return self.cursor.execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\utils.py", line 98, in __exit__ six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Python34\lib\site-packages\django\utils\six.py", line 658, in reraise raise value.with_traceback(tb)
File "C:\Python34\lib\site-packages\django\db\backends\utils.py", line 64, in execute return self.cursor.execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\backends\mysql\base.py", line 124, in execute return self.cursor.execute(query, args)
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-amd64.egg\MySQLdb\cursors.py", line 207, in execute self.errorhandler(self, exc, value)
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-amd64.egg\MySQLdb\connections.py", line 37, in defaulterrorhandler raise errorvalue
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-amd64.egg\MySQLdb\cursors.py", line 192, in execute r = self._query(query)
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-amd64.egg\MySQLdb\cursors.py", line 356, in _query rowcount = self._do_query(q)
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-amd64.egg\MySQLdb\cursors.py", line 320, in _do_query db.query(q)
django.db.utils.ProgrammingError: (1064, "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 '%s' at line 1")
我还参考并尝试按照本站点其他类似查询中的说明(安装了mysql-connector-python-2.1.3)进行操作,但似乎没有任何效果

完整的堆栈跟踪如下所示:

django.db.utils.ProgrammingError: (1064 ....)
django.db.utils.ProgrammingError: (1064, "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 '%s' at line 1")
D:\pythonLearn\learningDjango\mysite>python manage.py migrate
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\django\db\backends\utils.py", line 64, in execute return self.cursor.execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\backends\mysql\base.py", line 124, in execute return self.cursor.execute(query, args)
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-md64.egg\MySQLdb\cursors.py", line 207, in execute self.errorhandler(self, exc, value)
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-md64.egg\MySQLdb\connections.py", line 37, in defaulterrorhandler raise errorvalue
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-md64.egg\MySQLdb\cursors.py", line 192, in execute r = self._query(query)
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-md64.egg\MySQLdb\cursors.py", line 356, in _query rowcount = self._do_query(q)
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-md64.egg\MySQLdb\cursors.py", line 320, in _do_query db.query(q)
_mysql_exceptions.ProgrammingError: (1064, "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 '%s' at line 1")

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 354, in execute_from_command_line utility.execute()
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 346, in execute self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 394, in run_from_argv self.execute(*args, **cmd_options)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 445, in execute output = self.handle(*args, **options)
File "C:\Python34\lib\site-packages\django\core\management\commands\migrate.py", line 93, in handle executor = MigrationExecutor(connection, self.migration_progress_callback)
File "C:\Python34\lib\site-packages\django\db\migrations\executor.py", line 19, in __init__self.loader = MigrationLoader(self.connection)
File "C:\Python34\lib\site-packages\django\db\migrations\loader.py", line 47, in __init__self.build_graph()
File "C:\Python34\lib\site-packages\django\db\migrations\loader.py", line 188, in build_graph   self.applied_migrations = recorder.applied_migrations()
File "C:\Python34\lib\site-packages\django\db\migrations\recorder.py", line 59, in applied_migrations self.ensure_schema()
File "C:\Python34\lib\site-packages\django\db\migrations\recorder.py", line 53, in ensure_schema editor.create_model(self.Migration)
File "C:\Python34\lib\site-packages\django\db\backends\base\schema.py", line 289, in create_model self.deferred_sql.extend(self._model_indexes_sql(model))
File "C:\Python34\lib\site-packages\django\db\backends\mysql\schema.py", line 56, in _model_indexes_sql self.connection.cursor(), model._meta.db_table
File "C:\Python34\lib\site-packages\django\db\backends\mysql\introspection.py", line 142, in get_storage_engine
"WHERE table_name = %s", [table_name])
File "C:\Python34\lib\site-packages\django\db\backends\utils.py", line 79, in execute return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\backends\utils.py", line 64, in execute return self.cursor.execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\utils.py", line 98, in __exit__ six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Python34\lib\site-packages\django\utils\six.py", line 658, in reraise raise value.with_traceback(tb)
File "C:\Python34\lib\site-packages\django\db\backends\utils.py", line 64, in execute return self.cursor.execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\backends\mysql\base.py", line 124, in execute return self.cursor.execute(query, args)
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-amd64.egg\MySQLdb\cursors.py", line 207, in execute self.errorhandler(self, exc, value)
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-amd64.egg\MySQLdb\connections.py", line 37, in defaulterrorhandler raise errorvalue
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-amd64.egg\MySQLdb\cursors.py", line 192, in execute r = self._query(query)
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-amd64.egg\MySQLdb\cursors.py", line 356, in _query rowcount = self._do_query(q)
File "C:\Python34\lib\site-packages\mysql_python-1.2.4-py3.4-win-amd64.egg\MySQLdb\cursors.py", line 320, in _do_query db.query(q)
django.db.utils.ProgrammingError: (1064, "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 '%s' at line 1")

是的,你的mysql查询中有错误。请通过编辑将完整的错误回溯和导致错误的迁移文件添加到你的帖子中@Klaus D我已经在问题中添加了完整的堆栈跟踪。我不明白你所说的迁移文件是什么意思我想我们也需要你的模型的副本。@Klaus D甚至还没有创建模型,文档说,即使在创建任何应用程序之前,你也可以执行迁移,以确保一切正常