title: Sqlalchemy and PostgreSql: how to set primary key manually without conflicts in future?
body: <p>I have such table:</p>
  
  <pre><code>class Tag(Base):
      __tablename__ = 'tag'
  
      id = Column(Integer, primary_key=True)
      name = Column(Unicode(50), nullable=False)
  
      def __init__(self, name):
          self.name = name
  </code></pre>
  
  <p>Supose table is empty.
  Than I insert some data in such way:</p>
  
  <pre><code>t = Tag('first tag')
  t.id = 2
  dbsession.add(t)
  dbsession.commit()
  </code></pre>
  
  <p>And it's ok: I have one row in my postgresql table with id = 2.
  Next:</p>
  
  <pre><code>t = Tag('second tag')
  dbsession.add(t)
  dbsession.commit()
  </code></pre>
  
  <p>Than I have 2 rows: {id: 1, name: 'second tag'} and {id: 2, name: 'first_tag'} </p>
  
  <p>Next (final step):</p>
  
  <pre><code>t = Tag('third tag')
  dbsession.add(t)
  dbsession.commit()
  </code></pre>
  
  <blockquote>
    <p><strong>IntegrityError</strong>: (IntegrityError) duplicate key value violates unique constraint "tag_pkey" </p>
    
    <p>(it wants to create row with id = 2, but it is engaged already with first tag)</p>
  </blockquote>
  
  <p>Is it possible somehow to say to postgres: if such pkey is exist, try next until it will be available?</p>
  
  <p>It is very usefull when using dumps.</p>
  
  <p>Thanks in advance!</p>