我有一个已经在这里提到的问题 https://youtrack.jetbrains.com/issue/PY-44557
但我还没有找到解决方案。我正在使用 Python Flask 和 SQLAlchemy 来创建 API 服务。
这是我的进口:
from flask import Flask, jsonify, request
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import Column, Integer, String, Float
import os
from flask_marshmallow import Marshmallow
app = Flask(__name__)
basedir = os.path.abspath(os.path.dirname(__file__))
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///'+os.path.join(basedir, 'dealers.db')
db = SQLAlchemy(app)
ma = Marshmallow(app)
这是我的数据模型:
class Car(db.Model):
__tablename__ = 'cars'
car_id = Column(Integer, primary_key=True)
car_name = Column(String)
car_type = Column(String)
class CarSchema(ma.Schema):
class Meta:
fields = ('car_id', 'car_name', 'car_type')
car_schema = CarSchema()
cars_schema = CarSchema(many=True)
使用.query时,我的 UDF 出现问题/警告
def cars():
car_list = Car.query.all() # *Unresolved attribute reference 'query' for class 'Car'
result = cars_schema.dump(car_list)
return jsonify(result)