2013-12-10 42 views
2

我试图在centos machine中运行现有的项目。我从requirements.txt安装了包并安装成功但运行“python manage.py runserver”我得到以下回溯。python _mysql_exceptions.ProgrammingError:(2014,“Commands out of sync; you can not run this command now”)

[[email protected] bv]# python manage.py runserver 
Validating models... 

Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x98da9ec>> 
Traceback (most recent call last): 
    File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 91, in inner_run 
    self.validate(display_num_errors=True) 
    File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 266, in validate 
    num_errors = get_validation_errors(s, app) 
    File "/usr/local/lib/python2.7/site-packages/django/core/management/validation.py", line 103, in get_validation_errors 
    connection.validation.validate_field(e, opts, f) 
    File "/usr/local/lib/python2.7/site-packages/django/db/backends/mysql/validation.py", line 14, in validate_field 
    db_version = self.connection.get_server_version() 
    File "/usr/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 415, in get_server_version 
    self.cursor().close() 
    File "/usr/local/lib/python2.7/site-packages/debug_toolbar/utils/tracking/__init__.py", line 9, in wrapped 
    return callback(original, *args, **kwargs) 
    File "/usr/local/lib/python2.7/site-packages/debug_toolbar/panels/sql.py", line 21, in cursor 
    result = original(self) 
    File "/usr/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 306, in cursor 
    cursor = self.make_debug_cursor(self._cursor()) 
    File "/usr/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 387, in _cursor 
    self.connection = Database.connect(**kwargs) 
    File "/usr/local/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-linux-i686.egg/MySQLdb/__init__.py", line 81, in Connect 
    return Connection(*args, **kwargs) 
    File "/usr/local/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-linux-i686.egg/MySQLdb/connections.py", line 215, in __init__ 
    self.set_character_set(charset) 
    File "/usr/local/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-linux-i686.egg/MySQLdb/connections.py", line 294, in set_character_set 
    super(Connection, self).set_character_set(charset) 
_mysql_exceptions.ProgrammingError: (2014, "Commands out of sync; you can't run this command now") 

需要帮助来解决这个问题。 感谢

+0

重新安装python-mysql的 – Nilesh

+0

@NileshG为什么重新安装python-mysql的。 Mysql配置正确,我能够通过命令提示符查看数据库。我安装了mysql连接器1.2.3。更多我分别安装了mysql和python。 – user2681579

+0

如果我也运行syncdb,我得到相同的错误 – user2681579

回答

-1

您可以尝试在现有的数据库上运行 -

python manage.py inspectdb 

这将输出新models.py,现在你的models.py比较新生成的models.py

+0

我加倍检查now.I运行此命令时遇到同样的错误。需要帮助解决。 – user2681579

+0

我可以得到最后一个命令的任何更新。 – user2681579

1

如果你想许多执行SQL语句,不使用cur.execute(sql)

更好的方法是使用cur.executemany(sql)

EXP 1:这将导致一些错误

sql = "insert into test(name, age) value('Joe', '28');insert into test(name, age) value('xxtime', '15');" 
    cursor = db.cursor() 
    cursor.execute(sql) 
    db.commit() 

EXP 2:你可以用它来代替

sql = "insert into test(name, age) value(%s, %s);" 
    cursor = db.cursor() 
    cursor.executemany(sql,[('Joe', '28'),('xxtime', '15')]) 
    db.commit()