How we can migrate database in sqlmodel?
Asked Answered
P

1

7
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?

Payee answered 31/8, 2021 at 16:58 Comment(5)
alembic?Vierra
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).Bourgogne
This is a duplicate question of #68932599Philoctetes
In question @Philoctetes mentioned I tried to answer it. Hope it helpsSpeck
Does this answer your question? How to get Alembic to recognise SQLModel database model?Calycle
P
1

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

Purple answered 7/1, 2023 at 16:43 Comment(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.Vain

© 2022 - 2024 — McMap. All rights reserved.