Given a set of column names and their types, the goal is to
to instantiate a table and the corresponding mapped class.
It is related to question posted here: Dynamic Class Creation in SQLAlchemy.
So far I have the following:
table = Table(tbl,
metadata,
*(Column(col, ctype, primary_key=pk, index=idx) for col, ctype, pk, idx in zip(attrs, types, primary_keys, indexes))
)
This creates the table object. Now I need to create the corresponding class.
mydict={'__tablename__':tbl}
cls = type(cls_name, (Base,), mydict)
This gives me following error:
ArgumentError: Mapper Mapper|persons_with_coord|t_persons_w_coord could not assemble any primary key columns for mapped table
My question is how do I specify the primary keys as part of the class creation. And after the class is created do I need to call mapper as follows:
mapper(cls, table)