- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
.django_content_type' 不存在”-6ren"> .django_content_type' 不存在”-在我第一次尝试使用 django-reversion 期间,我正在评估它以查看我是否可以在我的模型上执行某些基本的版本检索操作: 在还原范围内保存对特定字段的更改后,我无法检索特定模型的先前版本列表,-6ren">
在我第一次尝试使用 django-reversion 期间,我正在评估它以查看我是否可以在我的模型上执行某些基本的版本检索操作:
在还原范围内保存对特定字段的更改后,我无法检索特定模型的先前版本列表,如下所示。尝试 reversion.get_for_object() 时,堆栈跟踪中出现以下错误:
DatabaseError: (1146, "Table 'pvtestmatrix.django_content_type' doesn't exist")
Django: v1.3.1
django-reversion: v1.5.7
安装了 django-reversion 并成功管理了一个 syncdb:
bash-3.2$ python manage.py syncdb
Creating tables ...
Creating table reversion_revision
Creating table reversion_version
Installing custom SQL ...
Installing indexes ...
No fixtures found.
在 settings.py 中添加了特定于还原的设置:
INSTALLED_APPS = (
# 'django.contrib.auth',
# 'django.contrib.contenttypes',
# 'django.contrib.sessions',
# 'django.contrib.sites',
# 'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.staticfiles',
'collabgrid.testmatrix',
'collabgrid.testcase',
'collabgrid.status',
'reversion',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.transaction.TransactionMiddleware',
'reversion.middleware.RevisionMiddleware',
)
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'PVTestMatrix',
...}
}
模型.py:
...
class Testmatrix(models.Model):
testmatrixid = models.AutoField(primary_key=True, db_column='TestMatrixId')
platform = models.CharField(max_length=60, db_column='Platform', blank=True)
...
class Meta:
db_table = u'TestMatrix'
def __str__(self):
return '%s__%s__%s' % (self.productid, self.testmatrixid, self.owner)
...
view.py 片段:
from collabgrid.testmatrix.models import Testmatrix
import reversion
reversion.register(Testmatrix)
tm=Testmatrix.objects.get(pk=729)
with reversion.create_revision():
tm.platform="AAA"
tm.save()
version_list = reversion.get_for_object(tm)
堆栈跟踪:
>>> from collabgrid.testmatrix.models import Testmatrix
>>> import reversion
>>>
>>> reversion.register(Testmatrix)
>>> tm=Testmatrix.objects.get(pk=729)
>>> with reversion.create_revision():
... tm.platform="AAA"
... tm.save()
...
Traceback (most recent call last):
File "<console>", line 3, in <module>
File "/Library/Python/2.6/site-packages/reversion/revisions.py", line 290, in __exit__
self._context_manager.end()
File "/Library/Python/2.6/site-packages/reversion/revisions.py", line 176, in end
in manager_context.iteritems()
File "/Library/Python/2.6/site-packages/reversion/revisions.py", line 175, in <genexpr>
for obj, data
File "/Library/Python/2.6/site-packages/reversion/revisions.py", line 602, in <lambda>
version_data = lambda: adapter.get_version_data(instance, VERSION_CHANGE, self._revision_context_manager._db)
File "/Library/Python/2.6/site-packages/reversion/revisions.py", line 97, in get_version_data
content_type = ContentType.objects.db_manager(db).get_for_model(obj)
File "/Library/Python/2.6/site-packages/django/contrib/contenttypes/models.py", line 38, in get_for_model
defaults = {'name': smart_unicode(opts.verbose_name_raw)},
File "/Library/Python/2.6/site-packages/django/db/models/manager.py", line 135, in get_or_create
return self.get_query_set().get_or_create(**kwargs)
File "/Library/Python/2.6/site-packages/django/db/models/query.py", line 378, in get_or_create
return self.get(**lookup), False
File "/Library/Python/2.6/site-packages/django/db/models/query.py", line 344, in get
num = len(clone)
File "/Library/Python/2.6/site-packages/django/db/models/query.py", line 82, in __len__
self._result_cache = list(self.iterator())
File "/Library/Python/2.6/site-packages/django/db/models/query.py", line 273, in iterator
for row in compiler.results_iter():
File "/Library/Python/2.6/site-packages/django/db/models/sql/compiler.py", line 680, in results_iter
for rows in self.execute_sql(MULTI):
File "/Library/Python/2.6/site-packages/django/db/models/sql/compiler.py", line 735, in execute_sql
cursor.execute(sql, params)
File "/Library/Python/2.6/site-packages/django/db/backends/util.py", line 34, in execute
return self.cursor.execute(sql, params)
File "/Library/Python/2.6/site-packages/django/db/backends/mysql/base.py", line 86, in execute
return self.cursor.execute(query, args)
File "/Library/Python/2.6/site-packages/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg/MySQLdb/cursors.py", line 174, in execute
self.errorhandler(self, exc, value)
File "/Library/Python/2.6/site-packages/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
DatabaseError: (1146, "Table 'pvtestmatrix.django_content_type' doesn't exist")
>>> version_list = reversion.get_for_object(tm)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Library/Python/2.6/site-packages/reversion/revisions.py", line 527, in get_for_object
return self.get_for_object_reference(obj.__class__, obj.pk, db)
File "/Library/Python/2.6/site-packages/reversion/revisions.py", line 506, in get_for_object_reference
content_type = ContentType.objects.db_manager(db).get_for_model(model)
File "/Library/Python/2.6/site-packages/django/contrib/contenttypes/models.py", line 38, in get_for_model
defaults = {'name': smart_unicode(opts.verbose_name_raw)},
File "/Library/Python/2.6/site-packages/django/db/models/manager.py", line 135, in get_or_create
return self.get_query_set().get_or_create(**kwargs)
File "/Library/Python/2.6/site-packages/django/db/models/query.py", line 378, in get_or_create
return self.get(**lookup), False
File "/Library/Python/2.6/site-packages/django/db/models/query.py", line 344, in get
num = len(clone)
File "/Library/Python/2.6/site-packages/django/db/models/query.py", line 82, in __len__
self._result_cache = list(self.iterator())
File "/Library/Python/2.6/site-packages/django/db/models/query.py", line 273, in iterator
for row in compiler.results_iter():
File "/Library/Python/2.6/site-packages/django/db/models/sql/compiler.py", line 680, in results_iter
for rows in self.execute_sql(MULTI):
File "/Library/Python/2.6/site-packages/django/db/models/sql/compiler.py", line 735, in execute_sql
cursor.execute(sql, params)
File "/Library/Python/2.6/site-packages/django/db/backends/util.py", line 34, in execute
return self.cursor.execute(sql, params)
File "/Library/Python/2.6/site-packages/django/db/backends/mysql/base.py", line 86, in execute
return self.cursor.execute(query, args)
File "/Library/Python/2.6/site-packages/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg/MySQLdb/cursors.py", line 174, in execute
self.errorhandler(self, exc, value)
File "/Library/Python/2.6/site-packages/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
DatabaseError: (1146, "Table 'pvtestmatrix.django_content_type' doesn't exist")
我在这里正确使用了还原吗?通过运行“reversion.get_for_object(tm)”,我希望在上一步发出“tm.save()”时看到至少包含最后保存版本的列表。
不确定此错误是否特定于还原处理,因为我能够提交对模型的更改,而我通常不会使用还原处理。提前致谢。
最佳答案
您的 django_content_type
表不存在,因为 django.contrib.contenttypes
在您的 INSTALLED_APPS
中被注释掉了。取消注释(删除 #
)并再次运行 syncdb。
关于mysql - django-reversion: get_for_object() 抛出数据库错误 "' <db_name>.django_content_type' 不存在”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17913604/
在我第一次尝试使用 django-reversion 期间,我正在评估它以查看我是否可以在我的模型上执行某些基本的版本检索操作: 在还原范围内保存对特定字段的更改后,我无法检索特定模型的先前版本列表,
我是一名优秀的程序员,十分优秀!