Error while runing flask migrate scripts
wildoctopus opened this issue · 5 comments
Getting this error while runing flask db migrate
sqlalchemy.exc.ProgrammingError: (psycopg2.errors.DuplicateTable) relation "idx_indian_geo" already exist
I exactly dont know whats the error.
Below is my model file -
class Indian(BaseModel):
"""Airports with its geospatial data."""
tablename="indian"
name = db.Column(db.String(255))
longitude = db.Column(db.Float)
latitude = db.Column(db.Float)
geo = db.Column(Geometry(geometry_type="POINT"))
def repr(self):
return "<Airport {name} ({lat}, {lon})>".format(name=self.name, lat=self.latitude, lon=self.longitude)
Please suggest what can be the error. I dropped and reacted my database as well and ran "flask db init, flask db migrate, again. But while executing flask db upgrade it gives error.
@wildoctopus this means that your latest migration is trying to create an index that already exists in your database. There is no single fix for this, you have to figure out why the migration is trying to create an index that was already created. At some point your database went out of sync with your models.
(also, why post the same comment twice?)
@miguelgrinberg I checked out for that index but didn't find that. So dropped that database completely and recreated a new one. But still it throws same error.
For my database model please take a look in - https://github.com/wildoctopus/geoappservice/blob/main/application/models/airport/india.py
And for the main code please see here - https://github.com/wildoctopus/geoappservice/blob/main/application/__init__.py
- Sorry for pasting this issue twice. I forgot to remove that.
Thanks
I don't think I can help with this. If the problem is not in your application or database, then you should ask the maintainers of your Geometry
column for assistance.
Finally able to find the solution for this. I commented the op.create_index part in migration script and it ran successfully.
import sqlalchemy as sa
from geoalchemy2.types import Geometry
# revision identifiers, used by Alembic.
revision = 'e785ead267ee'
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('indian_airports',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('name', sa.String(length=100), nullable=True),
sa.Column('longitude', sa.Float(), nullable=True),
sa.Column('latitude', sa.Float(), nullable=True),
sa.Column('geo', Geometry(geometry_type='POINT', from_text='ST_GeomFromEWKT', name='geometry'), nullable=True),
sa.PrimaryKeyConstraint('id')
)
**#op.create_index('idx_indian_airports_geo', 'indian_airports', ['geo'], unique=False, postgresql_using='gist', postgresql_ops={})**
# ### end Alembic commands ###
One thing here I didn't understood is why it was giving error while executing for the first time?
As I said before, this is the wrong project to ask about this. If I had to guess, this is an incompatiblity between Alembic (database migration support) and this Geometry custom column type that you are using.