I can't seem to figure out how to transition a query for the Ip Blocks/ranges than a given IP address exists in, from a generic query into a relationship. i keep getting foreign key errors, not matter what arguments I try. The simplest form of what I'm trying to do is below:
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Standard imports import sqlalchemy from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import relationship from sqlalchemy.orm import sessionmaker from sqlalchemy import Integer, Column, ForeignKey, Unicode from sqlalchemy import create_engine import sqlalchemy.dialects.postgresql # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # You probably don't need to overwrite this Base = declarative_base() # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Define some models that inherit from Base class IpAddress(Base): __tablename__ = 'ip_address' id = Column(Integer, primary_key=True) ip_address = Column(Unicode(16), nullable=False) ip_address__cidr = Column(sqlalchemy.dialects.postgresql.CIDR, nullable=False) class IpRange(Base): __tablename__ = 'ip_range' id = Column(Integer, primary_key=True) ip_range__cidr = Column(sqlalchemy.dialects.postgresql.CIDR, nullable=False) IpAddress.in_ip_ranges = relationship( IpRange, primaryjoin=IpAddress.ip_address__cidr.op('<<=')(IpRange.ip_range__cidr), viewonly=True, ) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # set the engine engine = create_engine('postgresql://sa_test:sa_test@localhost/sqlalchemy_test', echo=True) Base.metadata.create_all(engine) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # do a simple query to trigger the mapper error sessionFactory = sessionmaker(bind=engine) s = sessionFactory() s.query(IpAddress).get(1) -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.