79122725

Date: 2024-10-24 15:53:10
Score: 0.5
Natty:
Report link

For solve this problem I used the alembic tool (thanks to Robert)

Instruction how to use this tool:

1. Installing

First of all, we need to install alembic with command pip install alembic (or other in you're variant)

After that, we need to initializate the alimbic for our project with command alembic init alembic (alembic after the init is the path to create alembic folder)

2. Setting up

Now, we need to setup alembic to our project. Firstly, open the alembic.ini file in main directory of project, find this string and paste your url to database

# the output encoding used when revision files
# are written from script.py.mako
# output_encoding = utf-8

sqlalchemy.url = driver:///database.db

And open alembic/env.py file for adding metadata of your database

# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
target_metadata = database.metadata

3. Using

For editing database we need to use two commands:

  1. Saving a current version of database (also need with after initialization)
alembic revision --autogenerate -m "Your comment"
  1. And commiting all changes for your database file
alembic upgrade head

That's all! If I have any mistakes in this answer (grammar too) , please write in comments

Reasons:
  • Blacklisted phrase (0.5): thanks
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: kotek