Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python django 1.11.x->;2.x迁移。我得到了错误的';分组依据';领域_Python_Django - Fatal编程技术网

Python django 1.11.x->;2.x迁移。我得到了错误的';分组依据';领域

Python django 1.11.x->;2.x迁移。我得到了错误的';分组依据';领域,python,django,Python,Django,我刚刚升级了Django版本。我的应用程序中未修改模型或代码 但是。。。我在QuerySet中得到了不同的结果 打印“查询”时,“分组依据”中指定的字段不同 型号: class Content(models.Model): id_field = models.AutoField(db_column='id_', primary_key=True) ... collections = models.ManyToManyField('Collection',

我刚刚升级了Django版本。我的应用程序中未修改模型或代码

但是。。。我在QuerySet中得到了不同的结果

打印“查询”时,“分组依据”中指定的字段不同

型号:

class Content(models.Model):
    id_field = models.AutoField(db_column='id_', primary_key=True)
    ...
    collections = models.ManyToManyField('Collection',
                        through='CollectionMap', 
                        through_fields=('contentid', 'collectionid'))

class CollectionMap(models.Model):
    field_index = models.AutoField(db_column='_index', primary_key=True)
    collectionid = models.ForeignKey(Collection, on_delete=models.CASCADE, db_column='collectionid')
    contentid = models.ForeignKey(Content, on_delete=models.CASCADE, db_column='contentid')
    field_time = models.DateTimeField(db_column='_time')

class Collection(models.Model):
    field_index = models.AutoField(db_column='_index', primary_key=True)
    name = models.CharField(unique=True, max_length=50)
    collectionorder = models.IntegerField(db_column='collectionOrder', blank=True, null=True)
    active = models.IntegerField(blank=True, null=True)
    field_time = models.DateTimeField(db_column='_time')
代码:

查询:

1.11.X

SELECT
    Content.id_, Collection. name 
FROM Content
    LEFT OUTER JOIN Collection_Map ON (Content.id_ = Collection_Map.contentid)
    LEFT OUTER JOIN Collection ON (Collection_Map.collectionid = Collection._index)
GROUP BY Content.id_
ORDER BY Content.itemOrder DESC
LIMIT 50;
2.X

按字段分组:

版本1.11.X:按
内容分组
id
版本2.X:按
内容
id
集合
名称

我想要这个…“。。。按Content.id分组…'


我该怎么办???

您能在这里打印完整的查询吗?另外,
自动字段上的
分组依据
实现了什么?@rtindru“集合”具有不同的“名称”,但id_字段是相同的内容。我只想有一个“id字段”、“名称”by“分组依据”重复的“id字段”。你能为集合模型添加代码吗?@rtindru我添加了一个集合模型。我对1.11分组依据如何工作感到困惑。代码读取时,一个内容可以有多个集合,每个集合可以有不同的名称。因此,在collection name字段上按/aggregate分组很有意义。由于varchar上没有太多可聚合的内容,所以我认为groupby是有意义的。我错过了什么?
SELECT
    Content.id_, Collection. name 
FROM Content
    LEFT OUTER JOIN Collection_Map ON (Content.id_ = Collection_Map.contentid)
    LEFT OUTER JOIN Collection ON (Collection_Map.collectionid = Collection._index)
GROUP BY Content.id_
ORDER BY Content.itemOrder DESC
LIMIT 50;
SELECT
    Content.id_, Collection. name 
FROM Content
    LEFT OUTER JOIN Collection_Map ON (Content.id_ = Collection_Map.contentid)
    LEFT OUTER JOIN Collection ON (Collection_Map.collectionid = Collection._index)
GROUP BY Content.id_, Collection. name 
ORDER BY Content.itemOrder DESC
LIMIT 50;