Harendrra
Harendrra

Reputation: 135

I got flask sqlalchemyerror sqlalchemy.exc.InvalidRequestError: Multiple classes found for path

sqlalchemy version = 1.2.7

sqlalchemy.exc.InvalidRequestError: One or more mappers failed to initialize - can't proceed with initialization of other mappers. Triggering mapper: 'Mapper|Image|Image'. Original exception was: Multiple classes found for path "Visualization" in the registry of this declarative base. Please use a fully module-qualified path.
sqlalchemy.exc.InvalidRequestError: Multiple classes found for path "Visualization" in the registry of this declarative base. Please use a fully module-qualified path.
class Visualization(db.Model):
    __table_args__ = {'extend_existing': True}
    id = db.Column(db.Integer, primary_key=True)
    image_id = db.Column(db.Integer, db.ForeignKey('image.id'),
        nullable=False)
    name = db.Column(db.String(255))
    type=db.Column(db.String(255))
    path = db.Column(db.String(255))
    target_layer = db.Column(db.Integer)
    target_class = db.Column(db.Integer)

class Image(db.Model):
    __table_args__ = {'extend_existing': True}
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80))
    path = db.Column(db.String(80))
    thumbnail = db.Column(db.String(80))
    prediction = db.Column(db.Float)
    label = db.Column(db.String(80))
    class_index = db.Column(db.Integer)
    visualizations = db.relationship('Visualization', backref='image', lazy=True)

Upvotes: 0

Views: 457

Answers (2)

swimmer
swimmer

Reputation: 3313

The error is most likely caused by:

visualizations = db.relationship('Visualization', backref='image', lazy=True)

under class Image.

It seems to indicate that there is additional metadata in db.Model that makes Visualization ambiguous.

Assuming your model is defined in database/models/my_model.py, the issue should be solved by changing the relationship to:

visualizations = db.relationship('database.models.my_model.Visualization', backref='image', lazy=True)

Related SO here.

Upvotes: 1

Andrew Clark
Andrew Clark

Reputation: 880

Try this

visualizations = db.relationship('Visualization', backref=db.backref('image'), lazy=True)

Upvotes: 0

Related Questions