title: Flask - SQLAlchemy many to many causes sqlalchemy.orm.exc.FlushError
body: <pre><code>class Show(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      title = db.Column(db.String(200), unique=True, nullable=False)
      studio = db.relationship("ShowStudio", backref="show", cascade="delete")
  
  class Studio(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      name = db.Column(db.String(100), unique=True, nullable=False)
      show = db.relationship("ShowStudio", backref="studio", cascade="delete")
  
  class ShowStudio(db.Model):
      show_id = db.Column(db.Integer, db.ForeignKey(Show.id, ondelete="CASCADE"), primary_key=True)
      studio_id = db.Column(db.Integer, db.ForeignKey(Studio.id, ondelete="CASCADE"), primary_key=True)
  
  studio = Studio(name="asd")
  
  db.session.add(studio)
  s = Show(title="a", studio=[studio])
  db.session.flush()
  
  db.session.add(s)
  db.session.commit()
  </code></pre>
  
  <p>When I run it, it throws</p>
  
  <blockquote>
    <p>sqlalchemy.orm.exc.FlushError: Attempting to flush an item of type  as a member of collection "Studio.show". Expected an object of type  or a polymorphic subclass of this type.</p>
  </blockquote>
  
  <p>I follow the answer from <a href="https://stackoverflow.com/a/3179160/3673259">here</a>. I do not understand what cause the error. Any helps are welcome.</p>