I'm encountering an issue with Flask Admin's inline_models feature where it successfully displays data locally using MySQL Workbench, but throws errors when accessing the server with PHPMyAdmin. Both the local environment and the server are using MySQL, and the database schema is identical. However, when attempting to display inline models on the server through Flask Admin, it results in errors. I've verified that the server's database connection is functioning properly. What could be causing this discrepancy, and how can I troubleshoot and resolve it? Any insights or suggestions would be greatly appreciated. The local inline_model effect
The error message on the server side:
File "/var/www/html/flask-app/flask-venv/lib/python3.11/site-packages/flask_admin/contrib/sqla/form.py", line 678, in _calculate_mapping_key_pair raise Exception('Cannot find reverse relation for model %s' % info.model) Exception: Cannot find reverse relation for model <class 'myproject.models.Ordersinq'>
class OrdersView(AdminModelViewBASE):
# 設定要顯示的欄位以及搜尋、篩選功能
column_formatters = {
'Prod_no': lambda v, c, m, p: Markup(m.Prod_no.replace(',', '<br>')),
'Prod_quan': lambda v, c, m, p: Markup(m.Prod_quan.replace(',', '<br>')),
# 添加其他需要換行的欄位
}
column_filters = ['Order_no', 'Mem_no']
column_default_sort = ('Order_no', True)
inline_models = [
(
Ordersinq,
dict(
form_columns=['no', 'prod_name', 'Prod_size', 'prod_color', 'prod_quan', 'prod_fee', 'prod_deli_fee'],
column_labels={
'prod_name': '產品名稱',
'Prod_size': '尺寸',
'prod_color': '顏色',
'prod_quan': '數量',
'prod_fee': '價格',
'prod_deli_fee': '運費',
}
)
)
]
here is the relationship of the tables:
class Ordersinq(db.Model):
__tablename__ = 'ordersinq'
no = db.Column(db.Integer, primary_key=True, autoincrement=True)
orders_no = db.Column(db.String(255), db.ForeignKey('orders.Order_no'))
mem_no = db.Column(db.String(255), nullable=True)
prod_no = db.Column(db.String(255))
prod_color = db.Column(db.String(40))
prod_quan = db.Column(db.Integer)
prod_fee = db.Column(db.Integer)
prod_deli_fee = db.Column(db.Integer)
Prod_serial = db.Column(db.Integer)
Prod_size = db.Column(db.String(255))
prod_name = db.Column(db.String(255))
Orderprod_startfix = db.Column(db.Date)
Orderprod_endfix = db.Column(db.Date)
order = db.relationship('Orders', backref='ordersinq', lazy=True)
class Orders(db.Model):
__tablename__ = 'orders'
Order_no = db.Column(db.String(255), primary_key=True)
Prod_no = db.Column(db.String(1000), nullable=True)
Prod_quan = db.Column(db.String(1000), nullable=True)
Merch_no = db.Column(db.String(20), nullable=True)
Merch_quan = db.Column(db.Integer, nullable=True)
Even with identical package versions and databases, what could be causing the discrepancy where the code runs successfully locally but encounters errors on the server side?
I have checked the package versions and compared the databases, and they are all the same.