小编gsd*_*sdf的帖子

SQLAlchemy 的外键约束错误

我现在正在尝试在 SQLAlchemy 中从旧课程中实现非常简单的示例表...

我已经走了这么远但是当我运行代码时......

from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String, Date, MetaData
from sqlalchemy import ForeignKey
from sqlalchemy.orm import relationship
from sqlalchemy import create_engine

Base = declarative_base()
engine = create_engine('mysql://x @ amazonaws.com:3306/db', echo=True)
class Guest(Base):
    __tablename__ = "guests"
    guest_no = Column(String(4), primary_key=True)
    g_name = Column(String(20))
    g_address = Column(String(30))
    booking = relationship("Booking", back_populates="guests")
class Hotel(Base):
    __tablename__ = "hotels"
    hotel_no = Column(String(4), primary_key=True)
    h_name = Column(String(20))
    h_address = Column(String(30))
    room = relationship("Room", back_populates="hotels")
    booking = relationship("Booking", back_populates="hotels")
class …
Run Code Online (Sandbox Code Playgroud)

python mysql sqlalchemy mysql-python

0
推荐指数
1
解决办法
4923
查看次数

标签 统计

mysql ×1

mysql-python ×1

python ×1

sqlalchemy ×1