【问题标题】:Running test fails in django after GinIndex creation, ProgrammingError: relation "table_name_GeoLocation_id" already exists创建 GinIndex 后在 django 中运行测试失败,ProgrammingError: 关系“table_name_GeoLocation_id”已经存在
【发布时间】:2021-08-18 10:41:15
【问题描述】:

我已将 Lat Lng 浮点数迁移到 PointField 并在模型上添加了 GinIndex。

在 Django 上运行测试时,测试失败并出现以下错误,迁移正常。

django.db.utils.ProgrammingError: 关系“table_name_GeoLocation_id”已经存在

如果我在模型的下方注释掉,它就会通过。 test_db 似乎试图创建两次索引。

我能得到一些帮助吗?

indexes = [GinIndex(fields=["GeoLocation"])]

【问题讨论】:

  • 您好,您可以编辑您的帖子以显示一些代码,以便人们可以帮助您

标签: postgresql django-models


【解决方案1】:

我得到了答案,在 geodjango 中创建几何字段会自动为我们创建索引。除非我们专门将 spatial_index=False 传递给 PointField(),否则索引已经可用。

从上述问题中删除显式索引 indexes = [GinIndex(fields=["GeoLocation"])] 实际上已经解决了问题。谢谢!

【讨论】:

    猜你喜欢
    • 2018-10-06
    • 1970-01-01
    • 1970-01-01
    • 2018-03-25
    • 2016-03-21
    • 2020-03-09
    • 2021-03-17
    • 1970-01-01
    • 2016-04-11
    相关资源
    最近更新 更多