我是SQLAlchemy的新手,我只希望SQLAlchemy打印要控制台的语句。 这是我的代码。
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, ForeignKey, Integer, String
engine = create_engine('sqlite:///')
Base = declarative_base()
class Person(Base):
__tablename__ = 'person'
id = Column(Integer, primary_key=True)
name = Column(String(250), nullable=False)
class Address(Base):
__tablename__ = 'address'
id = Column(Integer, primary_key=True)
street_name = Column(String(250))
street_number = Column(String(250))
post_code = Column(String(250), nullable=False)
person_id = Column(Integer, ForeignKey('person.id'))
person = relationship(Person)
Base.metadata.create_all(engine)
答案 0 :(得分:1)
您必须在echo=True
功能中设置create_engine
替换
engine = create_engine('sqlite:///')
使用
engine = create_engine('sqlite:///:memory:', echo=True)
您还缺少一些进口商品。