title: SQLAlchemy - How to insert a Joined Table Inherited class instance when the parent is already persisted
body: <p>I declared two clases using SQLAlchemy <a href="http://docs.sqlalchemy.org/en/latest/orm/inheritance.html#joined-table-inheritance" rel="noreferrer">Joined Table Inheritance</a>. Additionally I am using <strong>Flask-SQLAlchemy</strong> and Flask.</p>
  
  <pre><code>class Parent(db.Model):
  
      id = db.Column(db.Integer, primary_key=True)
      name = db.Column(db.String(255))
      type = db.Column(db.String(50))
  
      __mapper_args__ = {
          'polymorphic_identity': 'parent',
          'polymorphic_on': type
      }
  
  
  class Child(Parent):
  
      id = db.Column(db.Integer, db.ForeignKey('parent.id'), primary_key=True)
      brand_id = db.Column(db.Integer, nullable=False)
  
      __mapper_args__ = {
          'polymorphic_identity': 'child',
      }
  </code></pre>
  
  <p>The relationship between parent and child tables are <strong>one to one</strong>, with optional occurrence in the child side.</p>
  
  <p>When I create a new instance of Child, add it to the session and commit it to the database, everything works as expected. SQLAlchemy sends an <strong><code>INSERT</code> statement to the parent table</strong> and then another <strong><code>INSERT</code> to the child table</strong>, all by itself, avoiding any Foreign Key constraint violation.</p>
  
  <p>In some point of the application, I want to add a new row in the child table referencing to a row that already exist in the parent table.</p>
  
  <p>When I create a new <strong><code>Child</code></strong> instance and assign it manually an existing id to the FK column and sent it to the database. I get an IntegrityError (duplicate unique constraint violation) because SQLAlchemy tries to create a new parent entry in the database with the id passed to the child instance.</p>
  
  <p>So, the real question is:</p>
  
  <p><strong>How can I tell to SQLAlchemy, that the parent entry already exist in the database and I just want to create the child entry?</strong></p>