I'm using the ORM side of SQLAlchemy, and I've defined one of my columns to have a foreign key relation to another model, using:
Base = declarative_base()
class Model1(Base):
__tablename__ = 'm1'
Name = Column(String, primary_key = True)
info = Column(String)
class Model2(Base):
__tablename__ = 'm2'
Name = Column(String, primary_key = True)
info = Column(String)
other_model = Column(String, ForeignKey('m1.Name'))
However, it doesn't seem to matter what I put in the other_model
attribute, it seems more than happy to commit it to the database, even if there is no Model1
instance that has that Name
.