title: SQLAlchemy does not automatically populate foreign key field when a relationship is used
body: <p>I have a simple one-to-many relationship. I have <code>Project</code> and <code>Device</code> classes. A <code>Project</code> can have multiple <code>Device</code>s.</p>
  
  <p>The program does not behave as I expect when I add a device to a project using the relationship.</p>
  
  <p>The complete program is here:</p>
  
  <pre><code>from sqlalchemy import Column, String, ForeignKey
  from sqlalchemy.ext.declarative import declarative_base
  from sqlalchemy.orm import relationship
  
  Base = declarative_base()
  
  
  class Project(Base):
      __tablename__ = "Projects"
  
      name = Column('Name', String(50), primary_key=True)
      devices = relationship("Device", back_populates="project")
  
  
  class Device(Base):
      __tablename__ = "Devices"
  
      serial_no = Column('SerialNo', String(50), primary_key=True)
      project_name = Column('ProjectName', String(50), ForeignKey("Projects.Name"))
      project = relationship("Project", back_populates="devices", foreign_keys=[project_name])
  
  
  if __name__ == "__main__":
      p = Project(name="MyProject")
      d = Device()
  
      print("Before adding device:")
      print(f"p.devices: {p.devices}")
      print(f"d.project: {d.project}")
      print(f"d.project_name: {d.project_name}")
  
      p.devices.append(d)
  
      print("After adding device:")
      print(f"p.devices: {p.devices}")
      print(f"d.project: {d.project}")
      print(f"d.project_name: {d.project_name}")
  </code></pre>
  
  <p>And here is the output:</p>
  
  <pre><code>Before adding device:
  p.devices: []
  d.project: None
  d.project_name: None
  After adding device:
  p.devices: [&lt;__main__.Device object at 0x000001FF049B22B0&gt;]
  d.project: &lt;__main__.Project object at 0x000001FF03DB0D30&gt;
  d.project_name: None
  </code></pre>
  
  <p>All outputs are as expected except the last one <code>d.project_name</code>. <code>d.project_name</code> still returns <code>None</code>. I expect this to be populated as <code>MyProject</code> as well since <code>d.project</code> returns that project object.</p>
  
  <p>What am I missing?</p>