1

I'm using Python 2.7+flask-sqlalchemy. I have the following models/table defined:

class Detail(db.Model):
    __tablename__ = 'details'
    id = db.Column(db.Integer, primary_key=True)
    ....

class Usage(db.Model):
    __tablename__ = 'details'
    id = db.Column(db.Integer, primary_key=True)
    details = db.relationship('Detail', secondary=details_usages, backref=db.backref('usages', lazy='dynamic'))
    ....

details_usages = db.Table('details_usages',
    db.Column('detail_id', db.Integer, db.ForeignKey('details.id')),
    db.Column('usage_id', db.Integer, db.ForeignKey('usages.id')),
    db.Column('is_required', db.Integer)
)

I have the following query:

models.Detail.query.join(details_usages).add_columns('details_usages.is_required').all()

I'm getting the following error:

NoSuchColumnError: "Could not locate column in row for column 'details_usages.is_required'"

What am I doing wrong?

1 Answer 1

3

I found the solution. The correct way of querying should be:

models.Detail.query.join(details_usages).add_columns(details_usages.c.is_required).all()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.