Skip to content

How to run a database migration when using SQLModel (such as Alembic)? #85

@joemudryk

Description

@joemudryk

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the SQLModel documentation, with the integrated search.
  • I already searched in Google "How to X in SQLModel" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to SQLModel but to Pydantic.
  • I already checked if it is not related to SQLModel but to SQLAlchemy.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

I created a simple app (based on the documentation using FastAPI and SQLModel)
This can be run with either Docker or a python virtual environment, to speed things up.

https://github.com/joemudryk/learning-sqlmodel

Description

I am trying to:

  1. Create a database from the existing model
  2. Update the model (or uncomment this line )
  3. Run a database migration such as Alembic
  4. Continue to use the application with the updated model and database

Any help would be greatly appreciated, and maybe the instructions can be used to help update the official documentation :)

Operating System

Linux

Operating System Details

Linux Mint 20.1

SQLModel Version

0.0.4

Python Version

3.9.6

Additional Context

I was able to use Alembic for the orm library ormar okay. The instructions for that can be found here:
https://collerek.github.io/ormar/models/migrations/

Maybe that will give some insight for the approach I took, or you will find a solution that I didn't.

Thank you in advanced.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions