Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 烧瓶SQLAlchemy:SQLAlchemy.exc.InvalidRequestError_Python_Sqlalchemy_Flask Sqlalchemy - Fatal编程技术网

Python 烧瓶SQLAlchemy:SQLAlchemy.exc.InvalidRequestError

Python 烧瓶SQLAlchemy:SQLAlchemy.exc.InvalidRequestError,python,sqlalchemy,flask-sqlalchemy,Python,Sqlalchemy,Flask Sqlalchemy,我如何解决这个问题 sqlalchemy.exc.InvalidRequestError: One or more mappers failed to initialize - can't proceed with initialization of other mappers. Triggering mapper: 'mapped class User->user'. Original exception was: Could not determine join condit

我如何解决这个问题

 sqlalchemy.exc.InvalidRequestError: One or more mappers failed to initialize -
 can't proceed with initialization of other mappers. 
 Triggering mapper: 'mapped class User->user'. Original exception was:
 Could not determine join condition between parent/child tables on relationship User.dm_first - there are multiple foreign key paths linking the tables.  
 Specify the 'foreign_keys' argument, providing a list of those columns 
 which should be counted as containing a foreign key reference to the parent table.
用户模型

class User(db.Model):
    """
    Users Class for creating the 'users' table in the database
    and for managing user's information
    """
    __tablename__ = 'user'
    id = db.Column(db.Integer, primary_key=True)
    firstname = db.Column(db.String(20), nullable=False)
    lastname = db.Column(db.String(20), nullable=False)
    username = db.Column(db.String(15), nullable=False, unique=True)
    email = db.Column(db.String(40), nullable=False)
    password = db.Column(db.Text, nullable=False)
    terms = db.Column(db.Boolean, unique=False, default=False)
    message = db.relationship('Message', lazy='subquery', backref='user',
                              order_by='Message.id')
    dm = db.relationship('DM', lazy='subquery', backref='user')



    def __repr__(self):
        """
        Returns the user's username when the __repr__ function is called.
        """
        return f"Username:{self.username}"

    def save(self):
        """ saves user's data """
        db.session.add(self)
        db.session.commit()
DM模型

class DM(db.Model):
    """ Direct Messages (DM) table in the database"""
    __tablename__ = 'DM'
    id = db.Column(db.Integer, primary_key=True)
    created = db.Column(db.DateTime, default=datetime.datetime.utcnow)
    user_one_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    user_two_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    messages = db.relationship('Message', backref='dm', lazy='dynamic')

    def __init__(self, id_one, id_two):
        self.user_one_id = id_one
        self.user_two_id = id_two

    def save(self):
        db.session.add(self)
        db.session.commit()
其目的是将DM(直接消息)模型连接到两个不同的 用户(用户id)。DM就像一个普通的私人消息功能