title: sqlalchemy schema: there is no unique constraint matching given keys for referenced table
body: <p>I'm trying to create 2 tables using SQLAlchemy models that are identical in structure but distinct in purpose, the <code>Whitelist</code> and <code>Blacklist</code> which also reference a <code>Magazine</code> (not shown). They both fkey to an instance of a Campaign (say a political campaign) which in turn has an fkey to a <code>Politician</code> model (also not shown).</p>
  
  <p>I'm picturing the <code>Whitelist</code>/<code>Blacklist</code> to be many:1 to the <code>Campaign</code> since there could be multiple white/blacklists for, but when running the migration I get <code>sqlalchemy.exc.ProgrammingError: (ProgrammingError) there is no unique constraint matching given keys for referenced table "campaigns"</code>. There also needs to be a M:1 from <code>Campaign</code> to <code>Politician</code>.</p>
  
  <p>Can someone please explain why this is causing a unique constraint error since the whitelist and blacklist are on separate tables? Also, how would I be able to make this relational schema work?</p>
  
  <pre><code>class Campaign(Base):
      __tablename__ = "campaigns"
      id = Column(Integer, primary_key=True, nullable=False)
      politician_id = Column(Integer, ForeignKey('politician.id'), nullable=False)
      description = Column(Text, nullable=True)
  
  
  class Whitelist(Base):
      __tablename__ = "whitelist"
      id = Column(Integer, primary_key=True, nullable=False)
      campaign_id = Column(Integer, ForeignKey('campaign.id'), nullable=False)
      magazine_id = Column(Integer, ForeignKey('magazine.id'), nullable=False)
  
  
  class Blacklist(Base):
      __tablename__ = "blacklist"
      id = Column(Integer, primary_key=True, nullable=False)
      campaign_id = Column(Integer, ForeignKey('campaign.id'), nullable=False)
      magazine_id = Column(Integer, ForeignKey('magazine.id'), nullable=False)
  </code></pre>