- Flask Framework Cookbook(Second Edition)
- Shalabh Aggarwal
- 191字
- 2021-06-24 13:58:06
How it works...
Now, let's say we modify the model of our product table to add a new field called company, as shown here:
class Product(db.Model): # ... # Same product model as last recipe # ... company = db.Column(db.String(100))
The result of migrate will be something like the following snippet:
$ flask db migrate INFO [alembic.runtime.migration] Context impl SQLiteImpl. INFO [alembic.runtime.migration] Will assume non-transactional
DDL. INFO [alembic.autogenerate.compare] Detected added column
'product.company'
Generating
<path/to/application>/flask_catalog/migrations/versions/2c08f71f9253_.py ... done
In the preceding code, we can see that Alembic compares the new model with the database table and detects a newly added column for company in the product table (created by the Product model).
Similarly, the output of upgrade will be something like the following snippet:
$ flask db upgrade INFO [alembic.runtime.migration] Context impl SQLiteImpl. INFO [alembic.runtime.migration] Will assume non-transactional
DDL. INFO [alembic.runtime.migration] Running upgrade None ->
2c08f71f9253, empty message
Here, Alembic performs the upgrade of the database for the migration detected earlier. We can see a hex code in the preceding output. This represents the revision of the migration performed. This is for internal use by Alembic to track the changes to database tables.