gpt4 book ai didi

python - sqlalchemy.exc.InvalidRequestError : Multiple classes found for path in the registry of this declarative base

转载 作者:行者123 更新时间:2023-12-04 11:33:15 24 4
gpt4 key购买 nike

当我为此模型 flask sqlalchemy 应用程序时,我不断收到以下错误:
sqlalchemy.exc.InvalidRequestError:在此声明性基的注册表中找到路径“地址”的多个类。请使用完全模块限定的路径。

我主要提到这个:http://flask-sqlalchemy.pocoo.org/2.3/quickstart/#simple-relationships

# The examples in this file come from the Flask-SQLAlchemy documentation
# For more information take a look at:
# http://flask-sqlalchemy.pocoo.org/2.1/quickstart/#simple-relationships

from datetime import datetime

from rest_api_demo.database import db


class Student(db.Model):
__table_args__ = {'extend_existing': True}
id = db.Column(db.Integer, primary_key=True)
first_name = db.Column(db.String(80))
address_id = db.Column(db.Integer, db.ForeignKey('address.id'),nullable=False)
address = db.relationship('Address',backref=db.backref('students',lazy='dynamic'))


def __init__(self, first_name,addr=None):
self.first_name = first_name
self.addr = address

class Address(db.Model):
#__tablename__ = 'address'
__table_args__ = {'extend_existing': True}
id = db.Column(db.Integer,primary_key = True)
street = db.Column(db.String(200))


def __init__(self, street):
self.street = street

最佳答案

当我重构代码而不运行任何数据库迁移时,有时会遇到此错误。

发生的事情是您的模型名称在您的数据库中没有表名来存储任何关系。

关于python - sqlalchemy.exc.InvalidRequestError : Multiple classes found for path in the registry of this declarative base,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46700274/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com