I'm developing a web application based on MySQL DBMS I followed the tutorial in that answer in which it creates all the tables related to every model calling the create_all().
The only one thing I don't understand is how to create only one table and not all of them. I searched through google but can't find an answer.
Column object represents a column in a database table. Constructor takes name, type and other parameters such as primary_key, autoincrement and other constraints. The create_all() function uses the engine object to create all the defined table objects and stores the information in metadata.
Step 1 - Install the Flask-SQLAlchemy extension. Step 2 - You need to import the SQLAlchemy class from this module. Step 3 - Now create a Flask application object and set the URI for the database to use. Step 4 - then use the application object as a parameter to create an object of class SQLAlchemy.
For this purpose, two tables are created in our SQLite database (college. db). The students table has the same structure as given in the previous section; whereas the addresses table has st_id column which is mapped to id column in students table using foreign key constraint.
you can use create method
Model.__table__.create(session.bind)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With