title: Many-to-one relationship in SQLAlchemy
body: <p>This is a beginner-level question.</p>
  
  <p>I have a catalog of mtypes:</p>
  
  <pre><code>mtype_id name
         1 'mtype1'
         2 'mtype2'
  [etc]
  </code></pre>
  
  <p>and a catalog of Objects, which must have an associated mtype:</p>
  
  <pre><code>obj_id mtype_id name
       1        1 'obj1'
       2        1 'obj2'
       3        2 'obj3'
  [etc]
  </code></pre>
  
  <p>I am trying to do this in SQLAlchemy by creating the following schemas:</p>
  
  <pre><code>mtypes_table = Table('mtypes', metadata,
   Column('mtype_id', Integer, primary_key=True),
   Column('name', String(50), nullable=False, unique=True),
  )
  
  objs_table = Table('objects', metadata,
   Column('obj_id', Integer, primary_key=True),
   Column('mtype_id', None, ForeignKey('mtypes.mtype_id')),
   Column('name', String(50), nullable=False, unique=True),
  )
  
  mapper(MType, mtypes_table)
  mapper(MyObject, objs_table, 
   properties={'mtype':Relationship(MType, backref='objs', cascade="all, delete-orphan")}
  )
  </code></pre>
  
  <p>When I try to add a simple element like:</p>
  
  <pre><code>mtype1 = MType('mtype1')
  obj1 = MyObject('obj1')
  obj1.mtype=mtype1
  session.add(obj1)
  </code></pre>
  
  <p>I get the error:</p>
  
  <pre><code>AttributeError: 'NoneType' object has no attribute 'cascade_iterator'
  </code></pre>
  
  <p>Any ideas?</p>