问题描述
按照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.创建用户表,然后我可以登录。
解决方法
Flask-AppBuilder将驼峰式名称(例如SoftwareProduct)映射到下划线表名称(例如software_product)中,但表名称是softwareproduct。要修复映射,请将类名称从“ SoftwareProduct”更改为“ Softwareproduct”。