pythonflaskflask-appbuilder

"No records found" with Flask-AppBuilder


Following the documentation on Model Views, I constructed the following model in 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))

The table "softwareproduct" exists in the database and has several entries. I assume that it automatically links the class "SoftwareProduct" to the table "softwareproduct", because I don't see any option to manually link it. If there is and that is missing, please tell me. There is a view for it in 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"
)

However when I start the application, I get "No records found". How can I get F.A.B. to display the existing records?

I use Python 3.8.5 with Flask 1.1.2 with a PostgreSQL database.

I know that the database connection works because F.A.B. creates the user tables and I can login.


Solution

  • Flask-AppBuilder maps camelcase names like SoftwareProduct into underscore table names like software_product but the table name is softwareproduct. To fix the mapping, change the class name from "SoftwareProduct" to "Softwareproduct".