多租户应用程序无法通过模型进行迭代

时间:2019-04-25 09:30:58

标签: python postgresql flask sqlalchemy flask-sqlalchemy

我正在使用本指南创建多租户应用程序: 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


任何帮助将不胜感激

2 个答案:

答案 0 :(得分:1)

我想您在定义方法之前错过了@simple_cache。或在任何情况下将Organization变量更新为其他None值。

答案 1 :(得分:0)

我发现了这个问题,似乎当我转到在postgres中没有特定数据库的URL时,它无法进行遍历。