title: Flask-SQLAlchemy - model has no attribute 'foreign_keys'
body: <p>I have 3 models created with Flask-SQLalchemy: User, Role, UserRole</p>
  <p>role.py:</p>
  <pre><code>class Role( ActiveRecord, db.Model ):
  
      __tablename__ = &quot;roles&quot;
  
      #   Schema
      id = db.Column( db.Integer, primary_key = True )
      name = db.Column( db.String( 24 ), unique = True )
      description = db.Column( db.String( 90 ) )
  
      users = db.relationship( &quot;User&quot;, secondary = &quot;UserRole&quot;, \
          backref = db.backref( &quot;roles&quot; ) )
  </code></pre>
  <p>user.py:</p>
  <pre><code>class User( db.Model, ActiveRecord ):
  
      __tablename__ = &quot;users&quot;
  
      #   Schema
      id = db.Column( db.Integer, primary_key = True )
      email = db.Column( db.String( 90 ), unique = True )
      password = db.Column( db.String( 64 ) )
  
      #   Relations
      roles = db.relationship( &quot;Role&quot;, secondary = &quot;UserRole&quot;, \
          backref = db.backref( &quot;users&quot; ) )
  </code></pre>
  <p>user_role.py:</p>
  <pre><code>class UserRole( ActiveRecord, db.Model ):
  
      __tablename__ = &quot;user_roles&quot;
  
      #   Schema
      user_id = db.Column( db.Integer, db.ForeignKey( 'users.id' ), primary_key = True )
      role_id = db.Column( db.Integer, db.ForeignKey( 'roles.id' ), primary_key = True )
  </code></pre>
  <p>If I try (in the console) to get all users via <code>User.query.all()</code> I get <code>AttributeError: 'NoneType' object has no attribute 'all'</code> and if I try again I get another error saying:</p>
  <pre><code>sqlalchemy.exc.InvalidRequestError: One or more mappers failed to initialize - can't proceed with initialization of other mappers.  Original exception was: type object 'UserRole' has no attribute 'foreign_keys'
  </code></pre>
  <p>Can anyone shed a light on what is it exactly that I'm doing wrong? I think I had this code running ok a few months ago, but I updated SQLAlchemy, Flask and Flask-SQLAlchemy recently and it stopped. It's just a side project.</p>