Postgresql (psycopg2.errors.DuplicateTable) 关系 "idx_xxx_geometry" 已经存在

Postgresql (psycopg2.errors.DuplicateTable) relation "idx_xxx_geometry" already exists

环境:

代码:

import pandas as pd
import geopandas as gpd
from sqlalchemy import create_engine

x = pd.read_csv("./ships.csv")
x = gpd.GeoDataFrame(x, geometry=gpd.points_from_xy(x.LON, x.LAT))

engine = create_engine("postgresql://postgres:root@localhost/db")
x.to_postgis('ships', engine, index=False)

结果:

sqlalchemy.exc.ProgrammingError: (psycopg2.errors.DuplicateTable) relation "idx_ships_geometry" already exists

[SQL: CREATE INDEX idx_ships_geometry ON public.ships USING gist (geometry)]
(Background on this error at: https://sqlalche.me/e/14/f405)

这是 GeoAlchemy 0.11 引起的已知错误。在 GeoAlchemy 中修复此问题之前,请使用旧版本 0.10.2 使其正常工作。有关详细信息,请参阅 https://github.com/geopandas/geopandas/issues/2375