# 通过对象的方式创建两张依赖关系的表 from sqlalchemy import * from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import relation, sessionmaker
Base = declarative_base()
class Movie(Base) : __tablename__ = 'movies'
id = Column(Integer, primary_key=True) title = Column(String(255), nullable=False) year = Column(Integer) directed_by = Column(Integer, ForeignKey('directors.id')) director = relation('Director', backref='movies', lazy=False)
def __init__(self, title=None, year=None) : self.title = title self.year = year