我对django的内置 comments 模型进行了一个简单的查询,并通过heroku的postgreSQL数据库得到以下错误:
DatabaseError: operator does not exist: integer = text LINE 1:
... INNER JOIN "django_comments" ON ("pi ns_pin"."id" = "django_...
^
HINT: No operator matches the given name and argument type(s).
You might need to add explicit type casts.
在谷歌上搜索之后,这个错误似乎在django被解决过很多次,但我仍然能理解(所有相关问题都在3-5年前就解决了).我使用的是django 1.4版和最新版本的tastypie.
该查询是在orm过滤器下进行的,并与我的开发数据库(sqlite3)完美配合:
class MyResource(ModelResource):
comments = fields.ToManyField('my.api.api.CmntResource', 'comments', full=True, null=True)
def build_filters(self, filters=None):
if filters is None:
filters = {}
orm_filters = super(MyResource, self).build_filters(filters)
if 'cmnts' in filters:
orm_filters['comments__user__id__exact'] = filters['cmnts']
class CmntResource(ModelResource):
user = fields.ToOneField('my.api.api.UserResource', 'user', full=True)
site_id = fields.CharField(attribute = 'site_id')
content_object = GenericForeignKeyField({
My: MyResource,
}, 'content_object')
username = fields.CharField(attribute = 'user__username', null=True)
user_id = fields.CharField(attribute = 'user__id', null=True)
有没有人有过在不编写原始SQL的情况下绕过这个错误的经验?