python - 多租户应用程序无法遍历模型
问题描述
我正在使用本指南创建多租户应用程序: 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
任何帮助,将不胜感激
解决方案
我猜你在定义方法之前错过了@simple_cache。或者组织变量在任何情况下都会更新为其他无值。
推荐阅读
- php - 选择一个 Secteur,然后在 Symfony 4 中获取所有属于该 Secteur 的分组
- amazon-web-services - 如何解决在 amazon aws、symfony 4 项目上找不到的 404 url
- python - 如何使用 scipy.optimize.minimize(...) 找到 z = f(x, y) 的最优参数(如椭圆)?
- python - 缺少 2 个必需的位置参数 - 类方法 Python
- java - 如何在一个动作中为数据结构的所有元素设置一个值(同时)
- php - 如何获取 AWS PHP 开发工具包以查找我存储在 Elastic Beanstalk 环境变量中的凭证?
- java - Jenkins 有没有办法检查我的 Java 代码是否是谷歌风格的格式,并且只有在格式正确的情况下才通过构建?
- sql - 您如何使用数据框、列表、向量等过滤到 R 中数据库中的表?
- python - 方格内空心方格
- java - VScode Java/Maven环境问题不同电脑