首页 > 解决方案 > 多租户应用程序无法遍历模型

问题描述

我正在使用本指南创建多租户应用程序: https ://medium.com/@smirnov.am/multitenancy-with-flask-6f5375a34f55

我遇到的问题是指南正在执行此操作:

@simple_cache
def get_known_tenants():
    tenants = Tenant.query.all()
    return [i.name for i in tenants]

我在这里做类似的事情:

def get_known_organizations():
    organizations = Organization.query.all()
    return [o.organization_name_url for o in organizations]

我是否遗漏了什么,因为我得到的错误是:

AttributeError: 'NoneType' object has no attribute 'query'

模型

class Organization(db.Model):
    organization_id = db.Column(db.Integer, primary_key=True)
    cypher = db.Column(db.String(10), unique=True, nullable=False)                  # 10-character String representation to use as ID of the organization
    organization_name = db.Column(db.String(100), unique=True, nullable=False)      # Organization name as String (ex: Seattle Children's Hospital)
    organization_name_url = db.Column(db.String(100), unique=True, nullable=False)  # Parsed organization name to lowercase and with dashes to use as subdomain (ex: seattle-childrens-hospital)
    website = db.Column(db.Text, unique=True, nullable=False)                       # URL of the organization's website
    contact_phone = db.Column(db.String(15), unique=True, nullable=False)           # Organization's contact number
    ooo_phone = db.Column(db.String(15), unique=True, nullable=False)               # Omedyari number


任何帮助,将不胜感激

标签: pythonpostgresqlflasksqlalchemyflask-sqlalchemy

解决方案


我猜你在定义方法之前错过了@simple_cache。或者组织变量在任何情况下都会更新为其他无值。


推荐阅读