1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] sqlalchemy.exc.InvalidRequestError: One or more mappers failed to initialize - can't...

Discussão em 'Python' iniciado por Stack, Setembro 14, 2025.

  1. Stack

    Stack Membro Participativo

    This error happened when I tried to get access to the page. I didn't get errors when I created the tables, but seems like there are problems still.

    The models are like this:

    class User(UserMixin, db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(64), index=True, unique=True)
    sell_items = db.relationship('Item', backref='user')

    class Item(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    item_name = db.Column(db.String(64), index=True)
    item_image = db.Column(db.String(200), index=True)
    price = db.Column(db.Float(10), index=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    user = db.relationship('User', backref='sell_items')


    The whole error message is this

    Triggering mapper: 'Mapper|User|user'. Original exception was: Error creating backref 'user' on relationship 'User.sell_items': property of that name exists on mapper 'Mapper|Item|item'


    How can I fix this? What I want to do is to refer to username who sells the item, but I cannot. There is a problem with the relationships between the models.

    Continue reading...

Compartilhe esta Página