Right now I’m doing this:
class MyTest(Base):
__tablename__ = 'mytest'
id = Column(Integer, primary_key = True)
name = Column(String(255), nullable=False)
created_at = Column(DateTime)
Base.metadata.create_all(engine)
But in the tutorial, another way is this:
user = Table('user', metadata,
Column('user_id', Integer, primary_key = True),
Column('user_name', String(16), nullable = False),
Column('email_address', String(60)),
Column('password', String(20), nullable = False)
)
Which method should I be using? By the way, I will be using sqlalchemy-migrate, (I don’t know if that will change the answer)
If you want to just access the data from the table and want to use SQLAlchemy as a mediator then you have to use
TABLE. But if you want to use the each row of the table as an separate object then you have to use declarative base.Which way you have to use is up to you and how you want to use SQLAlchemy.