我正在使用PostgreSQL创建Flask应用。我在终端中创建用户并运行我的应用程序,然后发生了错误。我以为可以解决这个问题,但无法解决。 https://help.navicat.com/hc/en-us/articles/218384757-Why-I-cannot-successfully-create-the-foreign-keys-。我的代码是这样的。
class User(Base):
__tablename__ = 'user'
id = Column(Integer, primary_key=True)
class Catalog(Base):
__tablename__ = 'catalog'
id = Column(Integer, primary_key=True)
catalogname = Column(String(250), nullable=False, unique=True)
user_id = Column(Integer, ForeignKey('user.id'))
user = relationship(User)
item = relationship('Item', cascade='all, delete-orphan')
class Item(Base):
__tablename__ = 'item'
itemname = Column(String(80), nullable=False)
id = Column(Integer, primary_key=True)
catalogname = Column(String(80), ForeignKey('catalog.catalogname'))
catalog = relationship(Catalog)
user_id = Column(Integer, ForeignKey('user.id'))
user = relationship(User)