I've seen other questions with a similar error though their fixes did not solve my issue. Notice that I'm using Flask-SQLAlchemy.
Here is my models file:
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)
As you may see, I want questions.subject to refer to subjects.subject. I try to form a query:
topicList = db.session.query(questions.topic.distinct()).filter_by(subject=subjectID, accountID=accountID)
I receive an error stating AttributeError: 'unicode' object has no attribute '_sa_instance_state'
What does this error mean and how to I fix my code to prevent this error? Thanks.