我正在尝试调试RALPH(使用DJANGO框架与MySQL交互的服务器)。我已经看到了这个问题,但最终答案还不清楚。请考虑我是一个python newby。服务器实际上无法正常工作,并在日志报告django异常时返回Server Error (500)
(见下文)。
从cursors.py中获取_do_query()
...
def _do_query(self, q):
db = self._get_db()
self._last_executed = q
db.query(q)
self._do_get_result()
return self.rowcount
...
和来自connections.py的query() ...
def query(self, query):
# Since _mysql releases GIL while querying, we need immutable buffer.
if isinstance(query, bytearray):
query = bytes(query)
if self.waiter is not None:
self.send_query(query)
self.waiter(self.fileno())
self.read_query_result()
else:
_mysql.connection.query(self, query)
...
这是所有日志回溯:
Traceback (most recent call last):
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 124, in execute
return self.cursor.execute(query, args)
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/MySQLdb/cursors.py", line 250, in execute
self.errorhandler(self, exc, value)
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/MySQLdb/connections.py", line 50, in defaulterrorhandler
raise errorvalue
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/MySQLdb/cursors.py", line 247, in execute
res = self._query(query)
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/MySQLdb/cursors.py", line 412, in _query
rowcount = self._do_query(q)
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/MySQLdb/cursors.py", line 375, in _do_query
db.query(q)
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/MySQLdb/connections.py", line 276, in query
_mysql.connection.query(self, query)
_mysql_exceptions.OperationalError: (1054, "Unknown column 'assets_asset.start_usage' in 'field list'")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/django/core/handlers/base.py", line 132, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python3.6/contextlib.py", line 52, in inner
return func(*args, **kwds)
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/django/contrib/admin/options.py", line 618, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/django/utils/decorators.py", line 110, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/django/views/decorators/cache.py", line 57, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/django/contrib/admin/sites.py", line 233, in inner
return view(request, *args, **kwargs)
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/reversion/revisions.py", line 297, in do_revision_context
return func(*args, **kwargs)
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/ralph/admin/mixins.py", line 141, in changelist_view
response = super().changelist_view(request, *args, **kwargs)
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/ralph/admin/mixins.py", line 313, in changelist_view
request, extra_context
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/ralph/admin/mixins.py", line 223, in changelist_view
return super().changelist_view(request, extra_context)
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/reversion/admin.py", line 419, in changelist_view
return super(VersionAdmin, self).changelist_view(request, context)
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/django/utils/decorators.py", line 34, in _wrapper
return bound_func(*args, **kwargs)
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/django/utils/decorators.py", line 110, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/django/utils/decorators.py", line 30, in bound_func
return func.__get__(self, type(self))(*args2, **kwargs2)
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/django/contrib/admin/options.py", line 1657, in changelist_view
selection_note=_('0 of %(cnt)s selected') % {'cnt': len(cl.result_list)},
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/django/db/models/query.py", line 144, in __len__
self._fetch_all()
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/django/db/models/query.py", line 965, in _fetch_all
self._result_cache = list(self.iterator())
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/ralph/lib/polymorphic/models.py", line 113, in iterator
for obj in model_query:
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/django/db/models/query.py", line 162, in __iter__
self._fetch_all()
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/django/db/models/query.py", line 965, in _fetch_all
self._result_cache = list(self.iterator())
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/django/db/models/query.py", line 238, in iterator
results = compiler.execute_sql()
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 840, in execute_sql
cursor.execute(sql, params)
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/django/db/utils.py", line 98, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 124, in execute
return self.cursor.execute(query, args)
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/MySQLdb/cursors.py", line 250, in execute
self.errorhandler(self, exc, value)
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/MySQLdb/connections.py", line 50, in defaulterrorhandler
raise errorvalue
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/MySQLdb/cursors.py", line 247, in execute
res = self._query(query)
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/MySQLdb/cursors.py", line 412, in _query
rowcount = self._do_query(q)
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/MySQLdb/cursors.py", line 375, in _do_query
db.query(q)
File "/opt/ralph/ralph-core/lib/python3.6/site-packages/MySQLdb/connections.py", line 276, in query
_mysql.connection.query(self, query)
django.db.utils.OperationalError: (1054, "Unknown column 'assets_asset.start_usage' in 'field list'")