Graphene pydantic 'NoneType' 对象没有属性 'connection'
Graphene pydantic 'NoneType' object has no attribute 'connection'
我将 FastApi 与石墨烯和石墨烯-pydantic 一起使用。
当我尝试创建一个对象时,即:
mutation createZone {
createZone(zoneDetails: {
zoneFr: "test fr",
zoneEn: "test en",
})
{
id
zoneFr
zoneEn
}
}
我收到错误:
graphql.error.located_error.GraphQLLocatedError: 'NoneType' object has no attribute 'connection'
我的突变是:
class CreateZone(graphene.Mutation):
class Arguments:
zone_details = ZoneGrapheneInputModel()
Output = ZoneGrapheneModel
@staticmethod
def mutate(parent, info, zone_details):
zone = Zone()
zone.zoneFr = zone_details.zoneFr
zone.zoneEn = zone_details.zoneEn
zone.save()
return zone
我也在使用 Orator 通过 CLI 创建表,我是不是遗漏了什么?
谢谢
编辑 1:
我的连接是这样的:
DATABASES = {
"mysql": {
"driver": "mysql",
"host": "127.0.0.1",
"database": "test_db",
"user": "root",
"password": "",
"prefix": "",
"port": 3306
}
}
db = DatabaseManager(DATABASES)
schema = Schema(db)
Model.set_connection_resolver(db)
已修复。我在 Orator 生成的模型中将 from orator import Model
更改为 from db import Model
。
我将 FastApi 与石墨烯和石墨烯-pydantic 一起使用。 当我尝试创建一个对象时,即:
mutation createZone {
createZone(zoneDetails: {
zoneFr: "test fr",
zoneEn: "test en",
})
{
id
zoneFr
zoneEn
}
}
我收到错误:
graphql.error.located_error.GraphQLLocatedError: 'NoneType' object has no attribute 'connection'
我的突变是:
class CreateZone(graphene.Mutation):
class Arguments:
zone_details = ZoneGrapheneInputModel()
Output = ZoneGrapheneModel
@staticmethod
def mutate(parent, info, zone_details):
zone = Zone()
zone.zoneFr = zone_details.zoneFr
zone.zoneEn = zone_details.zoneEn
zone.save()
return zone
我也在使用 Orator 通过 CLI 创建表,我是不是遗漏了什么? 谢谢
编辑 1: 我的连接是这样的:
DATABASES = {
"mysql": {
"driver": "mysql",
"host": "127.0.0.1",
"database": "test_db",
"user": "root",
"password": "",
"prefix": "",
"port": 3306
}
}
db = DatabaseManager(DATABASES)
schema = Schema(db)
Model.set_connection_resolver(db)
已修复。我在 Orator 生成的模型中将 from orator import Model
更改为 from db import Model
。