我有一个使用 SQLAlchemy 的应用程序,当我使用 SQLite 时它运行良好。然而,当我迁移到 PostgreSQL 时,我发现自己甚至无法进行合并。这是我用于无法合并项目的表的模型:
class Item(db.Model):
__tablename__ = "prices"
defindex = db.Column(db.Integer, primary_key=True)
quality = db.Column(db.Integer, primary_key=True)
craftable = db.Column(db.Boolean, primary_key=True)
tradeable = db.Column(db.Boolean, primary_key=True)
item_metadata = db.Column(db.String(70), primary_key=True)
name = db.Column(db.String(70), primary_key=True)
currency = db.Column(db.String(70))
price = db.Column(db.Float)
price_high = db.Column(db.Float)
这是我尝试进行合并的方法(假设所有变量都分配了正确的值):
new_item = Item(defindex=int(defindex), quality=int(quality), craftable=bool(is_craft),
tradeable=bool(is_trade), item_metadata=int(priceindex), currency=str(currency),
price=float(price), price_high=float(price), name=str(name))
但在这次通话中,我收到错误:
sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) operator does not exist: character varying = integer
LINE 3: ... prices.tradeable = true AND prices.item_metadata = 0 AND pr...
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
[SQL: 'SELECT prices.defindex AS prices_defindex, prices.quality AS prices_quality, prices.craftable AS prices_craftable, prices.tradeable AS prices_tradeable, prices.item_metadata AS prices_item_metadata, prices.name AS prices_name, prices.currency AS prices_currency, prices.price AS prices_price, prices.price_high AS prices_price_high \nFROM prices \nWHERE prices.defindex = %(param_1)s AND prices.quality = %(param_2)s AND prices.craftable = %(param_3)s AND prices.tradeable = %(param_4)s AND prices.item_metadata = %(param_5)s AND prices.name = %(param_6)s'] [parameters: {'param_1': 1067, 'param_3': True, 'param_6': 'Grandmaster', 'param_5': 0, 'param_4': True, 'param_2': 1}]
我尝试在创建时添加所有类型转换new_item
,但是没有用,错误依然存在。我应该做什么来修复它?