我知道我可以使用Table定义一个表:
user = Table('user', metadata,
Column('user_id', Integer, primary_key = True),
)
并使用Base:
Base = declarative_base()
class User(Base):
__tablename__ = 'user'
user_id= Column(Integer, primary_key = True)
但有什么不同?
答案 0 :(得分:2)
Base = declarative_base()
class User(Base):
__tablename__ = 'user'
id = Column('id', Integer, primary_key=True)
name = Column('name', Unicode(64))
只是
的语法糖metadata = MetaData()
user = Table('user', metadata,
Column('id', Integer, primary_key=True),
Column('name', Unicode(64)),
)
class User(object):
pass
mapper(User, user) # this will modify the User class!