我需要帮助,当我尝试在现有数据库中加入选择时出现以下错误 (它来自客户端,我只有读取权限(选择)我无法在任何方面修改它)
可能是模型类中的错误,但我是 Peewee ORM 的新手,我也不知道如何声明这些关系:::
(工作)C:\Users\eguzman\Documents\python-work\asterisk-insert-reminder>python script.py Traceback(最近调用最后):文件“script.py”,第 41 行,在 row.agegendas.CODIGO , row.ageagendas.PER_ID, row.stkpersonas.DOCUMENTO)) AttributeError: 'AgeCitas' 对象没有属性 'stkpersonas'
代码:script.py
import peewee as pw
from classes.model import MySqlDbModel, AgeCitas, AgeAgendas, StkPersonas
class SelectCitasToRemind(MySqlDbModel):
@staticmethod
def selectCitasToRemind():
cit = AgeCitas.alias()
age = AgeAgendas.alias()
per = StkPersonas.alias()
query = (cit.select(
cit.CIT_ID, cit.AGE_ID, cit.FECHAHORA,
age.AGE_ID, age.CODIGO, age.CEN_ID, age.PER_ID,
per.PER_ID, per.DOCUMENTO, per.NOMBRE)
.join(age, pw.JOIN.LEFT_OUTER, on=(cit.AGE_ID == age.AGE_ID))
.join(per, pw.JOIN.LEFT_OUTER, on=(age.PER_ID == per.PER_ID))
.where((cit.CIT_ID.is_null(False))
& (cit.PAC_ID.is_null(False))
)
.limit(10)
)
return query
query = SelectCitasToRemind.selectCitasToRemind()
for row in query:
print("{} | {} | {} | {} | {} | {}".format(
row.CIT_ID, row.AGE_ID, row.FECHAHORA,
row.ageagendas.CODIGO, row.ageagendas.PER_ID, row.stkpersonas.DOCUMENTO))
代码:classes/model.py
import peewee as pw
# Conection to mydbname database
dbn = 'mydbname'
user = 'myusername'
pwd = '******'
host = 'localhost'
prt = 3306
db = pw.MySQLDatabase(dbn, user=user,
password=pwd, host=host, port=prt)
class MySqlDbModel(pw.Model):
class Meta:
database = db
class AgeCitas(MySqlDbModel):
CIT_ID = pw.BigIntegerField()
AGE_ID = pw.BigIntegerField()
FECHAHORA = pw.DateTimeField()
ACT_ID = pw.BigIntegerField()
PAC_ID = pw.BigIntegerField()
ASIGNADA = pw.CharField()
IND_ID = pw.BigIntegerField()
ACUDIO = pw.DoubleField()
ORDEN = pw.DoubleField()
class Meta:
table_name = 'AGE_CITAS'
class AgeAgendas(MySqlDbModel):
AGE_ID = pw.DecimalField()
CODIGO = pw.CharField()
CEN_ID = pw.DecimalField()
PER_ID = pw.DecimalField()
NPR_ID = pw.DecimalField()
DESCRIPCION = pw.CharField()
COLOR = pw.CharField()
class Meta:
table_name = 'AGE_AGENDAS'
class StkPersonas(MySqlDbModel):
PER_ID = pw.BigIntegerField()
DOCUMENTO = pw.CharField()
NOMBRE = pw.CharField()
APELLIDO1 = pw.CharField()
APELLIDO2 = pw.CharField()
FECHA_ALTA = pw.DateTimeField()
FECHA_BAJA = pw.DateTimeField()
EMAIL = pw.CharField()
TELEFONO1 = pw.CharField()
TELEFONO2 = pw.CharField()
TELEFONO3 = pw.CharField()
TELEFONO4 = pw.CharField()
SEXO = pw.CharField()
NACIMIENTO = pw.DateTimeField()
ES_PACIENTE = pw.CharField()
ES_PROFESIONAL = pw.CharField()
class Meta:
table_name = 'STK_PERSONAS'