6
class Hero(SQLModel, table=True):
    id: int = Field(primary_key=True)
    name: str
    age: int = Field(default=None)
    status:str

I created the table using SQLModel.metadata.create_all(engine), when I changed the type of status to str and run the create_all() method again the type of status did not change in the database. Is there any way to migrate the database like Django or flask-migrate?

JIST
  • 1,139
  • 2
  • 8
  • 30
faris404
  • 343
  • 1
  • 3
  • 11
  • 3
    [alembic](https://alembic.sqlalchemy.org/en/latest/)? – finswimmer Aug 31 '21 at 18:17
  • 1
    It's SQLAlchemy behind the scenes, so alembic would be the natural choice for migrations (which is the same as used by `flask-migrate`, iirc). – MatsLindh Sep 01 '21 at 08:50
  • 3
    This is a duplicate question of https://stackoverflow.com/questions/68932099/how-to-get-alembic-to-recognise-sqlmodel-database-model – Greg Sep 05 '21 at 11:11
  • 1
    In question @Greg mentioned I tried to answer it. Hope it helps – Antonio Margaretti Sep 05 '21 at 13:35
  • Does this answer your question? [How to get Alembic to recognise SQLModel database model?](https://stackoverflow.com/questions/68932099/how-to-get-alembic-to-recognise-sqlmodel-database-model) – Kop3sh Dec 11 '22 at 09:45

1 Answers1

2

The fastest way is to drop the table manually and reload the app.

But if you want a more automated and reliable solution check the following link:

https://github.com/tiangolo/sqlmodel/issues/85

Kostas Nitaf
  • 428
  • 1
  • 2
  • 12
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 07 '23 at 19:36