Alembic autogenerate wants to remove foreign key indexes #598
Replies: 3 comments
-
the same problem occurs with field that has a unique index: class User(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
username: str = Field(unique=True)
i.e. |
Beta Was this translation helpful? Give feedback.
-
the db is SQLite in case that matters |
Beta Was this translation helpful? Give feedback.
-
Ok, found the reason for this:
so the fix for me was to add |
Beta Was this translation helpful? Give feedback.
-
First Check
Commit to Help
Example Code
Description
I initially created my db using
SQLModel.metadata.create_all(engine)
This added a foreign key index on the above table
gamesession_user_id
as you would expectNow I am adding Alembic migrations to my project
In my alembic
env.py
I have imported my models and given the SQLModel metadata:when I run
alembic check
oralembic revision --autogenerate
I get:and for the latter the generated revision drops the index
So it seems like Alembic doesn't understand the foreign keys on SQLModel models properly
Operating System
macOS
Operating System Details
No response
SQLModel Version
0.0.8
Python Version
Python 3.11.1
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions