How do I use class in SQLAlchemy. I have being trying to use class but the table is not creating

33 views Asked by At

The table is not creating and I dont want to use declarative_base and sqlalchemy.orm

I was told to use class but I don't know how to arrange it.

class Tables():
    def __init__(self, engine, metadata, table, name, age, location):
        self.engine = sqlengine
        self.metadata = sql_metadata
        self.table = table_name
        self.name = data_name
        self.age = data_age
        self.location = data_location

    def make_table(self):
        with self.engine.connect() as connection:
            member = Table(self.table, self.metadata,
                           Column("id", Integer, primary_key=True),
                           Column(self.name, String, unique=True),
                           Column(self.age, Integer),
                           Column(self.location, String)
                           )
        sql_metadata.create_all(sqlengine)

        with sqlengine.connect() as connection:
            sql_metadata.reflect(bind=sqlengine)
            for table in sql_metadata.tables.values():
                print(table)
0

There are 0 answers