0

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)
2
  • @snakecharmerb No, i haven't any extra class named Visualization" Commented Apr 2, 2021 at 16:30
  • This needs a minimal reproducible example. Commented Apr 5, 2021 at 10:23

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Try this

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

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.