I am trying to fetch dates from my MySQL Workbench database. But I get a "None" result in the terminal. How would this be achieved?. I'm trying to use the ORM of FastApi Framework.
Someone can help me please?.
models:
class PortabilidadInfo(Base):
__tablename__ = "portabilidad"
msisdn = Column(Integer, primary_key=True)
operator_id = Column(Integer, nullable=True)
last_port = Column(Date, default=datetime.now(), nullable=True)
Code:
last_portability = row[7] # 2022-04-03 06:00:00
last_portability_obj = datetime.strptime(last_portability, '%Y-%m-%d %H:%M:%S')
print("OBJ FECHA: ", last_portability_obj, type(last_portability_obj))
## FETCH DATE DATA FROM DATABASE
date_info = session.query(PortabilidadInfo).get(last_portability_obj)
print("XXXXXX: ", date_info, type(date_info))
I found the solution. I will copy the code below.
## BUSCO FECHA EN CSV ##
last_portability = row[7] # 2022-04-03 06:00:00 'str'
print("FECHA CSV: ", last_portability, type(last_portability))
# FETCH DATE DATA FROM DATABASE
date_info = session.query(PortabilidadInfo).filter(
PortabilidadInfo.last_port == last_portability).first()
print("FECHA BDD: ", date_info, type(date_info))
TERMINAL:
FECHA CSV: 2020-04-23 6:00:00 <class 'str'>
FECHA BDD: <models.portabilidad.PortabilidadInfo object at 0x7fdc38cc3470> <class 'models.portabilidad.PortabilidadInfo'>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.