Skip to content
Advertisement

FASTAPI SQLAlchemy Creating a table during run time based on user input

The user will be providing some information such as table_x with column_x. And I’d like to create these tables in an existing database or a new database based on the user’s value.

These values will be provided during run-time therefore I cannot create the Model beforehand.

If anyone could provide some help, let me know!

Advertisement

Answer

I’ve managed to figure out what I intended to do. I used engine.dialect.has_table(engine, Variable_tableName) to check if the database has the table inside. IF it doesn’t, then it will proceed to create a table in the database.

Sample code:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement