【问题标题】:"No records found" with Flask-AppBuilder使用 Flask-AppBuilder “未找到记录”
【发布时间】:2020-12-09 16:16:20
【问题描述】:

按照Model Views 上的文档,我在models.py 中构建了以下模型:

class SoftwareProduct(Model):
    suffix = Column(String(200), primary_key=True)
    label =  Column(String(200), nullable=False)
    comment =  Column(String)                                                                                                                                                                                                                                                                                                 
    coderepository =  Column(String(200))

“softwareproduct”表存在于数据库中,并且有多个条目。 我假设它自动将类“SoftwareProduct”链接到表“softwareproduct”,因为我没有看到任何手动链接它的选项。如果有并且缺少,请告诉我。 在views.py有一个视图:

class SoftwareProductView(ModelView):
    datamodel = SQLAInterface(SoftwareProduct)                                                                                                                                                                                                                                                                                
    label_columns = {'label':'Name', 'comment':'Comment'}

[...]

db.create_all()
                                                                                                                                                                                                                                                                                                                              
appbuilder.add_view(
    SoftwareProductView,
    "Software Product",
    icon = "fa-folder-open-o",
    category = "Software Product",
    category_icon = "fa-envelope"
)

但是,当我启动应用程序时,我收到“未找到记录”。我怎样才能获得 F.A.B.显示现有记录?

我使用 Python 3.8.5 和 Flask 1.1.2 和 PostgreSQL 数据库。

我知道数据库连接有效,因为 F.A.B.创建用户表,我可以登录。

【问题讨论】:

    标签: python flask flask-appbuilder


    【解决方案1】:

    Flask-AppBuilder 将像 SoftwareProduct 这样的驼峰名称映射到像 software_product 这样的下划线表名,但表名是 softwareproduct。要修复映射,请将类名从“SoftwareProduct”更改为“Softwareproduct”。

    【讨论】:

      猜你喜欢
      • 2018-05-21
      • 1970-01-01
      • 2018-07-13
      • 2019-07-26
      • 2020-06-24
      • 1970-01-01
      • 1970-01-01
      • 2019-01-21
      • 2013-02-05
      相关资源
      最近更新 更多