mkdir app
cd app
Now, create a virtual enviroment to isolate our project dependencies:
python -m venv venv
source venv/bin/activate # On Windows, use "venv\Scripts\activate"
pip install fastapi[all] uvicorn[standart] sqlalchemy alembic
How that we have defined our model, let`s create the SQLite database and tables
alembic init alembic
if you alembic handles migrations follow this method: In the alembic folder edit env.py and find target_metadata line and edit like the following
# alembic/env.py
# NOTE we addedd
from app.db.base import Base
target_metadata = Base.metadata
Open the alembic.ini file in the alembic directory and make the following changes:
# alembic.ini
[alembic]
script_location = alembic
sqlalchmey.url = sqlite:///./sqlite3.db # Replace with your database URL if different
alembic revision --autogenerate -m "Initial migration"
alembic upgrade head
python main.py