I had a simple table:
class test(Base):
__tablename__ = 'test'
id = Column(Integer, primary_key=True)
title = Column(String)
def __init__(self, title):
self.title = title
When using this table, id was set automatically. I want to add another field that is unique and efficient to search, so I added the field:
id2 = Column(String, primary_key=True)
And updated the constructor:
def __init__(self, id2, title):
self.id2 = id2
self.title = title
Now, id is no longer automatically set, or rather I get the error:
IntegrityError: (IntegrityError) test.id may not be NULL u'INSERT INTO test (id2, title) VALUES (?, ?)' [u'a', u'b']
Is there a way to maintain a second primary key without removing the autoincrement behavior of the first?