Flask uses sqlalchemy to dynamically add the configuration of binds and can switch at will.

problem description

A flask project now has a concept of one project, and all functions are operated under this project. What I want to do now is to create a new database for a new project. Reuse the model that has been written, and all database structures are the same. How can we reuse the code?

the environmental background of the problems and what methods you have tried

ok, now I know that sqlalchemy supports binding multiple databases, you can switch databases through binds, you can connect to mysql and create new databases through pymysql. However, in how to get the newly created database into the binds, the values of binds in the document are all the database addresses we have created.

Mar.30,2021
Menu