3

The flask-sqlalchemy documentation is very short, and shows how to create all the tables from a file with classes representing those tables.

a table class is something like this :

from flask import Flask
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
db = SQLalchemy(app)

class Table(db.Model):
    id = db.Column(db.Integer)
    name = db.Column(db.String)

db.create_all()

This will create a table into whatever database is specified with the 'app' config

What I wanna do is to create tables using a simple form

how can I create a single table dynamically ?

something like

def createTable(column1,column2):
    #create table
2
  • 1
    Some reading to get started: stackoverflow.com/questions/973481/…, stackoverflow.com/questions/43721680/…, stackoverflow.com/questions/25225320/… Commented Oct 30, 2019 at 16:27
  • 1
    Thank you very much, all of those question speak about bare sqlalchemy which is a a little differenet from flask-sqlalchemy, I don't want to use both as my code might get messy that way, so i'm trying to stick to flask-sqlalchemy, and i believe i've found a solution by creating a class dynamically and then call db.create_all() just afterwards, I'd like to create just that peticular table but it seems that function does not exist in flask-sqlalchemy that i know of, and create_all() does not affect other already created tables, so there's that .. Commented Oct 30, 2019 at 16:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.