我的本地Django正忙着运行在我们的服务器上运行的manage.py syncdb脚本。
这是我在运行python manage.py syncdb
,
操作错误:(1193,“未知系统变量'TRANSACTION'”)
它看起来像MySQL问题,仅供参考我在虚拟环境中使用Django 1.5.1安装MySQL-python 1.2.4并运行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。
我仍然想知道到底发生了什么。
答案 0 :(得分:6)
使用
DATABASES = {
'default': { 'NAME': 'test', 'ENGINE': 'django.db.backends.mysql', 'USER': 'redacted', 'PASSWORD': 'redacted', 'HOST': 'localhost' 'OPTIONS': { "init_command": "SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED"}
},
}
即没有“storage_engine = INNODB”。最新版本的MySql引擎默认为INNODB。
答案 1 :(得分:0)
sudo mysqld --version
default-storege-engine
因此,您的OPTIONS
设置应为:
{
'OPTIONS': { "init_command": "SET default_storage_engine=INNODB"}
}
sudo mysqld --verbose --help | grep storage