Ame*_*eyj 7 python orm flask flask-sqlalchemy
当我为此模型烧瓶 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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1462 次 |
| 最近记录: |