当我为此模型添加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
答案 0 :(得分:0)
有时候我在不执行数据库任何迁移的情况下进行代码重构时会遇到此错误。
发生的事情是您的模型名称在数据库中没有存储任何关系的表名。