Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create only ONE table with Flask + SqlAlchemy

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.

like image 775
rh0x Avatar asked Dec 12 '15 14:12

rh0x


People also ask

How do I create a specific table in SQLAlchemy?

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.

How do you create a table using SQLAlchemy in Flask?

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.

How do I create multiple tables in 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.


1 Answers

you can use create method

Model.__table__.create(session.bind)
like image 135
r-m-n Avatar answered Oct 17 '22 07:10

r-m-n