title: SQLAlchemy: AttributeError: 'tuple' object has no attribute 'foreign_keys' when making association table
body: <p>I just set up an association table, so i'm sure there's an error with how I wrote my relationships, but I've been looking over everything for an hour now and can't find it.</p>
  <p>my stack trace is telling me the error might have something to do with user join conditions, but i believe i set up the relationships correctly (the migrations ran before with the code written like this):</p>
  <pre><code>followers_table = Table('users_followers', db.Model.metadata,
                          db.Column('follower_id',
                                    db.Integer,
                                    db.ForeignKey('users.id')),
                          db.Column('following_id',
                                    db.Integer,
                                    db.ForeignKey('users.id')))
  
  awards_table = Table('users_awards', db.Model.metadata,
                       db.Column('user_id',
                                 db.Integer,
                                 db.ForeignKey('users.id')),
                       db.Column('award_id',
                                 db.Integer,
                                 db.ForeignKey('awards.id')))
  </code></pre>
  <p>and the user model:</p>
  <pre><code>class User(db.Model, UserMixin):
      __tablename__ = 'users'
      query = db.session.query_property()
  
      id = db.Column(db.Integer, primary_key=True, unique=True)
      first_name = db.Column(db.String, nullable=False)
      last_name = db.Column(db.String, nullable=False)
      username = db.Column(db.String(40), nullable=False, unique=True)
      email = db.Column(db.String(255), nullable=False, unique=True)
      avatar_url = db.Column(db.String)
      bio = db.Column(db.String)
      points_earned = db.Column(db.Integer)
      completed_workouts = db.Column(db.Integer)
      miles_run = db.Column(db.Integer)
      hashed_password = db.Column(db.String(255), nullable=False)
      following = relationship('User', secondary=followers_table,
                               primaryjoin=(
                                   followers_table.c.follower_id == id),
                               secondaryjoin=followers_table.c.following_id == id)
      followers = relationship('User', secondary=followers_table,
                               primaryjoin=(
                                   followers_table.c.following_id == id),
                               secondaryjoin=followers_table.c.follower_id == id)
      awards = relationship('Award', secondary=awards_table,
                            backref=&quot;user&quot;)
      comment_likes = relationship('Comment', secondary=c_likes,
                                   backref=&quot;liked_by&quot;)
      post_likes = relationship('User_Post', secondary=p_likes,
                                backref=&quot;liked_by&quot;)
  
      @ property
      def password(self):
          return self.hashed_password
  
      @ password.setter
      def password(self, password):
          self.hashed_password = generate_password_hash(password)
  
      def check_password(self, password):
          return check_password_hash(self.password, password)
  
      def to_dict(self):
          return {
              &quot;id&quot;: self.id,
              &quot;first_name&quot;: self.first_name,
              &quot;last_name&quot;: self.last_name,
              &quot;username&quot;: self.username,
              &quot;email&quot;: self.email,
              &quot;points_earned&quot;: self.points_earned,
              &quot;bio&quot;: self.bio,
          }
  
      def to_dict_full(self):
          return {
              &quot;id&quot;: self.id,
              &quot;first_name&quot;: self.first_name,
              &quot;last_name&quot;: self.last_name,
              &quot;username&quot;: self.username,
              &quot;email&quot;: self.email,
              &quot;avatar_url&quot;: self.avatar_url,
              &quot;points_earned&quot;: self.points_earned,
              &quot;bio&quot;: self.bio,
              &quot;followers&quot;: [follower.to_dict() for follower in self.followers],
              &quot;following&quot;: [leader.to_dict() for leader in self.following],
              &quot;awards&quot;: [award.to_dict() for award in self.awards],
              &quot;posts&quot;: [post.to_dict() for post in self.posts],
          }
  </code></pre>
  <p>but after I added another association table, everything went haywire:</p>
  <pre><code>workout_exercises = Table('workout_exercises', db.Model.metadata,
                            db.Column('exercise_id',
                                      db.Integer,
                                      db.ForeignKey('exercises.id')),
                            db.Column('workout_id',
                                      db.Integer,
                                      db.ForeignKey('workouts.id'))),
  </code></pre>
  <p>this isn't even referencing the user table, so the error has me confused. i can run the migrations, but when i try to seed the tables is when i get this error:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;/home/ryoung7986/00_solo-project/fit-yeah-app/.venv/bin/flask&quot;, line 8, in &lt;module&gt;
      sys.exit(main())
    File &quot;/home/ryoung7986/00_solo-project/fit-yeah-app/.venv/lib/python3.8/site-packages/flask/cli.py&quot;, line 967, in main
      cli.main(args=sys.argv[1:], prog_name=&quot;python -m flask&quot; if as_module else None)
    File &quot;/home/ryoung7986/00_solo-project/fit-yeah-app/.venv/lib/python3.8/site-packages/flask/cli.py&quot;, line 586, in main
      return super(FlaskGroup, self).main(*args, **kwargs)
    File &quot;/home/ryoung7986/00_solo-project/fit-yeah-app/.venv/lib/python3.8/site-packages/click/core.py&quot;, line 782, in main
      rv = self.invoke(ctx)
    File &quot;/home/ryoung7986/00_solo-project/fit-yeah-app/.venv/lib/python3.8/site-packages/click/core.py&quot;, line 1259, in invoke
      return _process_result(sub_ctx.command.invoke(sub_ctx))
    File &quot;/home/ryoung7986/00_solo-project/fit-yeah-app/.venv/lib/python3.8/site-packages/click/core.py&quot;, line 1259, in invoke
      return _process_result(sub_ctx.command.invoke(sub_ctx))
    File &quot;/home/ryoung7986/00_solo-project/fit-yeah-app/.venv/lib/python3.8/site-packages/click/core.py&quot;, line 1066, in invoke
      return ctx.invoke(self.callback, **ctx.params)
    File &quot;/home/ryoung7986/00_solo-project/fit-yeah-app/.venv/lib/python3.8/site-packages/click/core.py&quot;, line 610, in invoke
      return callback(*args, **kwargs)
    File &quot;/home/ryoung7986/00_solo-project/fit-yeah-app/.venv/lib/python3.8/site-packages/click/decorators.py&quot;, line 21, in new_func
      return f(get_current_context(), *args, **kwargs)
    File &quot;/home/ryoung7986/00_solo-project/fit-yeah-app/.venv/lib/python3.8/site-packages/flask/cli.py&quot;, line 426, in decorator
      return __ctx.invoke(f, *args, **kwargs)
    File &quot;/home/ryoung7986/00_solo-project/fit-yeah-app/.venv/lib/python3.8/site-packages/click/core.py&quot;, line 610, in invoke
      return callback(*args, **kwargs)
    File &quot;/home/ryoung7986/00_solo-project/fit-yeah-app/app/seeds/__init__.py&quot;, line 21, in seed
      seed_users()
    File &quot;/home/ryoung7986/00_solo-project/fit-yeah-app/app/seeds/users.py&quot;, line 9, in seed_users
      demo1 = User(first_name='Demo',
    File &quot;&lt;string&gt;&quot;, line 2, in __init__
    File &quot;/home/ryoung7986/00_solo-project/fit-yeah-app/.venv/lib/python3.8/site-packages/sqlalchemy/orm/instrumentation.py&quot;, line 388, in _new_state_if_none
      state = self._state_constructor(instance, self)
    File &quot;/home/ryoung7986/00_solo-project/fit-yeah-app/.venv/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py&quot;, line 883, in __get__
      obj.__dict__[self.__name__] = result = self.fget(obj)
    File &quot;/home/ryoung7986/00_solo-project/fit-yeah-app/.venv/lib/python3.8/site-packages/sqlalchemy/orm/instrumentation.py&quot;, line 214, in _state_constructor
      self.dispatch.first_init(self, self.class_)
    File &quot;/home/ryoung7986/00_solo-project/fit-yeah-app/.venv/lib/python3.8/site-packages/sqlalchemy/event/attr.py&quot;, line 322, in __call__
      fn(*args, **kw)
    File &quot;/home/ryoung7986/00_solo-project/fit-yeah-app/.venv/lib/python3.8/site-packages/sqlalchemy/orm/mapper.py&quot;, line 3413, in _event_on_first_init
      configure_mappers()
    File &quot;/home/ryoung7986/00_solo-project/fit-yeah-app/.venv/lib/python3.8/site-packages/sqlalchemy/orm/mapper.py&quot;, line 3301, in configure_mappers
      mapper._post_configure_properties()
    File &quot;/home/ryoung7986/00_solo-project/fit-yeah-app/.venv/lib/python3.8/site-packages/sqlalchemy/orm/mapper.py&quot;, line 1966, in _post_configure_properties
      prop.init()
    File &quot;/home/ryoung7986/00_solo-project/fit-yeah-app/.venv/lib/python3.8/site-packages/sqlalchemy/orm/interfaces.py&quot;, line 197, in init
      self.do_init()
    File &quot;/home/ryoung7986/00_solo-project/fit-yeah-app/.venv/lib/python3.8/site-packages/sqlalchemy/orm/relationships.py&quot;, line 2077, in do_init
      self._setup_join_conditions()
    File &quot;/home/ryoung7986/00_solo-project/fit-yeah-app/.venv/lib/python3.8/site-packages/sqlalchemy/orm/relationships.py&quot;, line 2141, in _setup_join_conditions
      self._join_condition = jc = JoinCondition(
    File &quot;/home/ryoung7986/00_solo-project/fit-yeah-app/.venv/lib/python3.8/site-packages/sqlalchemy/orm/relationships.py&quot;, line 2524, in __init__
      self._determine_joins()
    File &quot;/home/ryoung7986/00_solo-project/fit-yeah-app/.venv/lib/python3.8/site-packages/sqlalchemy/orm/relationships.py&quot;, line 2620, in _determine_joins
      self.secondaryjoin = join_condition(
    File &quot;&lt;string&gt;&quot;, line 2, in join_condition
    File &quot;&lt;string&gt;&quot;, line 2, in _join_condition
    File &quot;/home/ryoung7986/00_solo-project/fit-yeah-app/.venv/lib/python3.8/site-packages/sqlalchemy/util/deprecations.py&quot;, line 139, in warned
      return fn(*args, **kwargs)
    File &quot;/home/ryoung7986/00_solo-project/fit-yeah-app/.venv/lib/python3.8/site-packages/sqlalchemy/sql/selectable.py&quot;, line 959, in _join_condition
      constraints = cls._joincond_scan_left_right(
    File &quot;/home/ryoung7986/00_solo-project/fit-yeah-app/.venv/lib/python3.8/site-packages/sqlalchemy/sql/selectable.py&quot;, line 1014, in _joincond_scan_left_right
      b.foreign_keys, key=lambda fk: fk.parent._creation_order
  AttributeError: 'tuple' object has no attribute 'foreign_keys'
  </code></pre>
  <p>I'm baffled on this one. Hopefully it's a simple typo... thanks for any help!</p>