On 9/17/15 5:11 PM, Nana Okyere wrote:
So I have a form that will collect the name attribute of TableInfo.
Now, how do I dynamically - in runtime- create an empty table with the
name attribute given?
I'm not sure what this is asking. An "empty" table is this:
t = Table('mytable', metadata)
however, this is only a Python construct. It isn't in your database
schema.
Once table is created, I will use another form to collect field/column
names. Again, I'll like to dynamically add these columns to the table.
Column objects can be added using append_column:
http://docs.sqlalchemy.org/en/rel_1_0/core/metadata.html?highlight=append_column#sqlalchemy.schema.Table.append_column
t.append_column(Column(...))
but again, this does nothing to the database itself, we're still just
making an object in Python only and adding things to it.
Since this table and its columns won't be based on predefined models,
how do I create the table and columns in runtime in a way that the
application can interact with it?
once you have the fully formed Table object ready to go, you'd emit
Table.create(my_engine_or_connection). That will emit CREATE TABLE
statements to the database.
Background on these features and behaviors is at:
http://docs.sqlalchemy.org/en/rel_1_0/core/metadata.html?highlight=append_column#
Can I create tables on the fly in a flask-sqlalchemy environment? Thanks.
--
You received this message because you are subscribed to the Google
Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected]
<mailto:[email protected]>.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.