我的本地 Django 正在运行在我们服务器上运行的 manage.py syncdb 脚本。
这是我在运行时看到的错误消息python manage.py syncdb
,
OperationalError:(1193,“未知系统变量'TRANSACTION'”)
它看起来像一个 MySQL 问题,仅供参考我在虚拟环境中安装了 MySQL-python 1.2.4 和 Django 1.5.1,并且我正在运行 MySQL 版本 5.6.10。
这是我当前的完整虚拟环境pip list
,
Django (1.5.1)
MySQL-python (1.2.4)
pymongo (2.5.2)
python-cjson (1.0.5)
wsgiref (0.1.2)
我对 Django 不是很精通,谷歌搜索也没有任何结果,谁能告诉我这里可能发生了什么?
以下命令的完整引用
Traceback (most recent call last):
File "/Users/jamesmcmahon/src/business-intelligence/mongo2mysql/venv/lib/python2.7/site-packages/django/core/management/base.py", line 222, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/jamesmcmahon/src/business-intelligence/mongo2mysql/venv/lib/python2.7/site-packages/django/core/management/base.py", line 255, in execute
output = self.handle(*args, **options)
File "/Users/jamesmcmahon/src/business-intelligence/mongo2mysql/venv/lib/python2.7/site-packages/django/core/management/base.py", line 385, in handle
return self.handle_noargs(**options)
File "/Users/jamesmcmahon/src/business-intelligence/mongo2mysql/venv/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 56, in handle_noargs
cursor = connection.cursor()
File "/Users/jamesmcmahon/src/business-intelligence/mongo2mysql/venv/lib/python2.7/site-packages/django/db/backends/__init__.py", line 326, in cursor
cursor = util.CursorWrapper(self._cursor(), self)
File "/Users/jamesmcmahon/src/business-intelligence/mongo2mysql/venv/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 405, in _cursor
self.connection = Database.connect(**kwargs)
File "/Users/jamesmcmahon/src/business-intelligence/mongo2mysql/venv/lib/python2.7/site-packages/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/Users/jamesmcmahon/src/business-intelligence/mongo2mysql/venv/lib/python2.7/site-packages/MySQLdb/connections.py", line 187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
OperationalError: (1193, "Unknown system variable 'TRANSACTION'")
编辑:
我在我的 settings.py 中找到了导致问题的确切行
DATABASES = {
'default': {
'NAME': 'test',
'ENGINE': 'django.db.backends.mysql',
'USER': 'redacted',
'PASSWORD': 'redacted',
'HOST': 'localhost'
'OPTIONS': { "init_command": "SET storage_engine=INNODB, SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED" }
},
}
选项行在提交时解决了问题。我唯一能想到的是服务器正在运行 MySQL 5.5,而我在本地运行 5.6。
我仍然想弄清楚到底发生了什么。