title: sqlaclemy back_populates doesn't populate id field
body: <p>I have two models defined with sqlalchemy which have one-to-one relation. Simplifying things it will look something like this:</p>
  <pre><code>class First(Base):
      __tablename__ = &quot;first&quot;
      id = Column(Integer, primary_key=True)
      second_id = Column(Integer, ForeignKey(&quot;second.id&quot;))
      second = relationship(&quot;Second&quot;, uselist=False, back_populates=&quot;first&quot;)
  
  
  class Second(Base):
      __tablename__ = 'second'
      id = Column(Integer, primary_key=True)
      first_id = Column(Integer, ForeignKey(&quot;first.id&quot;))
      first = relationship(&quot;First&quot;, uselist=False, back_populates=&quot;second&quot;)
  </code></pre>
  <p>When I try adding a second object to an existing first, I'm getting an error:</p>
  <pre><code>first = First(id=1)
  session.add(first)
  session.commit()
  
  second = Second(first=first)
  session.add(second)
  session.commit()
  
  &gt;&gt;&gt; Traceback (most recent call last):
    File &quot;&lt;input&gt;&quot;, line 1, in &lt;module&gt;
    File &quot;/home/mhodis/.virtualenvs/project/local/lib/python2.7/site-packages/sqlalchemy/orm/session.py&quot;, line 2243, in flush
      self._flush(objects)
    File &quot;/home/mhodis/.virtualenvs/project/local/lib/python2.7/site-packages/sqlalchemy/orm/session.py&quot;, line 2369, in _flush
      transaction.rollback(_capture_exception=True)
    File &quot;/home/mhodis/.virtualenvs/project/local/lib/python2.7/site-packages/sqlalchemy/util/langhelpers.py&quot;, line 66, in __exit__
      compat.reraise(exc_type, exc_value, exc_tb)
    File &quot;/home/mhodis/.virtualenvs/project/local/lib/python2.7/site-packages/sqlalchemy/orm/session.py&quot;, line 2333, in _flush
      flush_context.execute()
    File &quot;/home/mhodis/.virtualenvs/project/local/lib/python2.7/site-packages/sqlalchemy/orm/unitofwork.py&quot;, line 391, in execute
      rec.execute(self)
    File &quot;/home/mhodis/.virtualenvs/project/local/lib/python2.7/site-packages/sqlalchemy/orm/unitofwork.py&quot;, line 556, in execute
      uow
    File &quot;/home/mhodis/.virtualenvs/project/local/lib/python2.7/site-packages/sqlalchemy/orm/persistence.py&quot;, line 181, in save_obj
      mapper, table, insert)
    File &quot;/home/mhodis/.virtualenvs/project/local/lib/python2.7/site-packages/sqlalchemy/orm/persistence.py&quot;, line 866, in _emit_insert_statements
      execute(statement, params)
    File &quot;/home/mhodis/.virtualenvs/project/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py&quot;, line 948, in execute
      return meth(self, multiparams, params)
    File &quot;/home/mhodis/.virtualenvs/project/local/lib/python2.7/site-packages/sqlalchemy/sql/elements.py&quot;, line 269, in _execute_on_connection
      return connection._execute_clauseelement(self, multiparams, params)
    File &quot;/home/mhodis/.virtualenvs/project/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py&quot;, line 1060, in _execute_clauseelement
      compiled_sql, distilled_params
    File &quot;/home/mhodis/.virtualenvs/project/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py&quot;, line 1200, in _execute_context
      context)
    File &quot;/home/mhodis/.virtualenvs/project/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py&quot;, line 1413, in _handle_dbapi_exception
      exc_info
    File &quot;/home/mhodis/.virtualenvs/project/local/lib/python2.7/site-packages/sqlalchemy/util/compat.py&quot;, line 203, in raise_from_cause
      reraise(type(exception), exception, tb=exc_tb, cause=cause)
    File &quot;/home/mhodis/.virtualenvs/project/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py&quot;, line 1193, in _execute_context
      context)
    File &quot;/home/mhodis/.virtualenvs/project/local/lib/python2.7/site-packages/sqlalchemy/engine/default.py&quot;, line 507, in do_execute
      cursor.execute(statement, parameters)
  IntegrityError: (psycopg2.IntegrityError) null value in column &quot;first_id&quot; violates not-null constraint
  DETAIL:  Failing row contains (1, null).
   [SQL: 'INSERT INTO second (first_id) VALUES (%(first_id)s RETURNING second.id'] [parameters: {'first': None}] (Background on this error at: http://sqlalche.me/e/gkpj)
  </code></pre>
  <p>My understanding was back_populates should handle assigning id's if we set object to relational field. What is wrong here?</p>