1
我对使用SQLAlchemy中的两个模块有点困惑。这是我的代码:在SQLAlchemy中使用关系和ForeignKey模块
Base = declarative_base()
class Restaurant(Base):
__tablename__ = 'restaurant'
id = Column(Integer, primary_key=True)
name = Column(String(250), nullable=False)
class MenuItem(Base):
__tablename__ = 'menu_item'
name =Column(String(80), nullable = False)
id = Column(Integer, primary_key = True)
description = Column(String(250))
price = Column(String(8))
course = Column(String(250))
restaurant_id = Column(Integer,ForeignKey('restaurant.id'))
restaurant = relationship(Restaurant)
据我所知,ForeignKey的用于定义MENU_ITEM表的restaurant_id列和餐厅表的id列的外键关系。但为什么餐厅=关系(餐厅)使用?