【发布时间】:2019-10-08 21:54:16
【问题描述】:
我正在将我的程序的代码库从 Peewee v2 更新到 v3。 在代码中,我在 select 语句中执行了一个子字符串,该语句在 v2 中始终有效,但现在不再有效。 我有下表
class Project(BaseModel):
project_id = CharField(column_name='projectID', primary_key=True)
name = CharField()
relative_path = CharField()
product_id = ForeignKeyField(column_name='productID', model=Product, field='product_id')
class Meta:
table_name = 'project'
indexes = (
(('name', 'product_id'), True),
)
我的查询如下:
project_prefix = "INH"
query = internal_projects = Project.select(fn.substring(Project.project_id, len(project_prefix) + 1))\
.where(Project.project_id.startswith(project_prefix))
for q in query:
print q
这给了我结果:
None
None
None
None
None
None
None
但是,如果我将 fn.substring 排除在查询之外,结果会很好,例如:
INH00001
INH00002
INH00004
INH00005
INH00006
INH00007
INH00008
我从第一个查询中得到“无”的次数确实与第二个查询的结果数量相匹配,所以它肯定选择了一些东西。如何使我的第一个查询再次工作,以便获得预期的结果?例如:
00001
00002
00004
00005
00006
00007
00008
【问题讨论】: