1. Install the extension, install Alembic in the virtual environment, do not know can go to see Pycharm series articles.
2. Initialize, before using Alembic, you need to create a Alembic project with the Alembic init command that creates a Alembic.ini profile and a Alembic file directory (your_alembic_dir).
The General command is Alembic Init migrate
My Windows environment, and do not want to set so many environment variables, with Pycharm,
Refer to the following configuration:
File--settings--tools--external Tools
Create a new one yourself with the plus sign on the right.
Name is what you will see in the menu. If you want to underline, give a few more, an underscore, can't see clearly
Program: is the location of Alembic, this is the location of alembic in my virtual environment.
Parameters: is an optional command parameter.
Working directory: This is where the command is executed.
Group: You can have a name for your project, as a group exists in your menu. Sometimes it's not good to write multiple items and run wrong.
This is the effect you just set.
Try to run a little bit.
The Migrate directory and the Alembic.ini file are generated under the project folder
3. Configuration:
Modify Alembic.ini To configure the database connection.
Comment out the original, write on our own. The path starts with the project path, which is the working directory we set up
; sqlalchemy.url = driver://user:pass@localhost/=sqlite:///plan.db
Configure the migrate/env.py, configure the data model.
# Target_metadata = None Import OS Import syssys.path.append (Os.path.dirname (Os.path.abspath(__file__"/. /")fromimport= Base.metadata
Find your own path, and then introduce SQLAlchemy's base
4. Generate a script file to upgrade the database
Alembic Revision--autogenerate
5. Perform the upgrade
Alembic Upgrade Head
Both the sound script and the execution upgrade can be written into the pycharm extension according to the init command.
Flask (10) Use Alembic, database structure management, upgrade, add table, add item