title: How to define composite primary key in SQLAlchemy
body: <p>I'm trying to use SQLAlchemy with MySQL to create a table mapping for a table with a composite primary key, and I'm unsure if I'm doing it right. The existing table is defined with the composite primary key. </p>
  
  <p>Here's the mapping class definition:</p>
  
  <pre><code>class table1(Base):
      __tablename__ = 'table1'
  
      col1 = Column(String, primary_key=True)
      col2 = Column(String, primary_key=True)
      col3 = Column(String)
  
      def __init__ = (self, col1, col2, col3):
          self.col1 = col1
          self.col2 = col2
          self.col3 = col3
  </code></pre>
  
  <p>this matches a record already in the database
      a = table1('test', 'test', 'test')</p>
  
  <p>If I add this to the session and add the records in the table, then work with the data, I get a MySQL error (1062 Duplicate Entry). </p>
  
  <pre><code>session.add(a)
  b = session.query(table1)
  for instance in b:
      print(instance.col1, instance.col2)
  </code></pre>
  
  <p>If I'm working with a single-key table, I get this error instead:</p>
  
  <pre><code>New instance &lt;table2 at 0x2f204d0&gt; with identity key 
  (&lt;class '__main__.table2'&gt;,('test',)) conflicts with 
  persistent instance &lt;table2 at 0x2f88770&gt;
  </code></pre>
  
  <p>Am I defining the composite primary key incorrectly? If not, what am I doing wrong further down for me to get the MySQL error instead of a Python/SQLAlchemy error? </p>