我正在尝试运行现有项目。我已经恢复了我的数据库并安装了所有必需的依赖项。运行syncdb时,我收到了以下错误。
[root@localhost ]# python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 459, in execute_manager
utility.execute()
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 231, in execute
self.validate()
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 :(得分:0)
你在复制sql语句吗?
例如:cursor.execute('show databases; show tables;')?
如果是这样,请尝试将它们分开:
cursor.execute( '') cursor.close 重新连接 重复
答案 1 :(得分:0)
正如@Kalinakov所说,这个错误是由于你的代码中使用了一些不正确的游标。请在代码中搜索cursor.execute并开始调试。
另请参阅下面的文章,其中提到了为什么会出现这种错误以及解决方案是什么 - Ways to avoid MySQLdb's "Commands out of sync; you can't run this command now" (2014) exception
答案 2 :(得分:0)
让我们开始一个小型调试之旅:
1)您的数据库是否正确配置?
让我们在没有mySQL数据库和SQlite的情况下尝试它。如果您没有任何编程错误 - SQLite将直接启动并同步您的数据库。为此,你需要去你的
settings.py
并将您的数据库重新配置为类似这样的内容:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'database.db',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
} }
2)现在,运行syncdb
并查看它是否有效。如果它现在有效,您可能需要重新配置数据库:name
,password
,host
和port
。如果SQlite不起作用 - 请回到这里并告诉我们确切的错误消息。