title: SQLAlchemy: AttributeError: 'unicode' object has no attribute '_sa_instance_state'
body: <p>I've seen other questions with a similar error though their fixes did not solve my issue. Notice that I'm using Flask-SQLAlchemy.</p>
  
  <p>Here is my models file:</p>
  
  <pre><code>class subjects(db.Model):
  
      id = db.Column(db.Integer, primary_key=True)
      subject = db.Column(db.String(100))
  
  class questions(db.Model):
  
      id = db.Column(db.Integer, primary_key=True)
      accountID = db.Column(db.Integer, db.ForeignKey('accounts.id'))
      subjectID = db.Column(db.Integer, db.ForeignKey('subjects.id'))
      subject = db.relationship('subjects')
      topic = db.Column(db.String(150), nullable=True)
  </code></pre>
  
  <p>As you may see, I want <code>questions.subject</code> to refer to <code>subjects.subject</code>. I try to form a query:</p>
  
  <pre><code>topicList = db.session.query(questions.topic.distinct()).filter_by(subject=subjectID, accountID=accountID)
  </code></pre>
  
  <p>I receive an error stating <code>AttributeError: 'unicode' object has no attribute '_sa_instance_state'</code></p>
  
  <p>What does this error mean and how to I fix my code to prevent this error? Thanks.</p>