0
votes

I am writing a code which has a booking system done on SQLite and on one of the CSV files it has time as a variable, I need it in a time type as I do operations on the time, but it gives the error message as

SQLite Time type only accepts Python time objects as input.

How do I get around this?

My code is below.

 class Flight(Base):
    __tablename__ = 'flights'

    id = Column(Integer, primary_key=True)
    planeid = Column(Integer, ForeignKey('planes.id'))
    leave = Column(Time)
    arrive = Column(Time)
    date = Column(Date)
    passengers = Column(Integer)
    destination = Column(String)

    bookings = relationship("Booking", back_populates='flights')
    plane = relationship("Plane", back_populates='flight')

...

 if session.query(Flight).count() == 0:
        with open("flights.csv", "r") as flights_file:
            lines = flights_file.readlines()
            for line in lines:
                _, planeid, leave, arrive, date, passengers, destination = line.rstrip().split(",")
                new_flight = Flight(planeid=planeid,
                                leave=leave,
                                arrive=arrive,
                                date=date,
                                passengers=passengers,
                                destination=destination)
                objects_to_add.append(new_flight)
    session.add_all(objects_to_add)
    session.commit()
1
Could you show where exactly you get this error? - Jakob F
it comes up when I run the schema - ben green
is there a specific bit of the code you want? - ben green

1 Answers

0
votes

Are you importing Time from sqlalchemy?
Please checkout this.

from sqlalchemy import (Column, Time)

arrive = Column(Time)