trying to import csv file into table in postgresql database on heroku, i am getting an error message: sqlalchemy.exc.DataError: (psycopg2.errors.InvalidTextRepresentation) invalid input syntax for type integer: "isbn". DATABASE_URL is set correctly. Here's my python code:
import csv
import os
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
engine = create_engine(os.getenv("DATABASE_URL"))
db = scoped_session(sessionmaker(bind=engine))
def main():
b = open("books.csv")
reader = csv.reader(b)
for isbn, title, author, year in reader:
db.execute("INSERT INTO books (isbn, title, author, year) VALUES (:isbn, :title, :author, :year)",
{"isbn": isbn, "title": title, "author": author, "year": year})
db.commit()
if __name__ == "__main__":
main()
my table, books, has isbn, title, author, and year. isbn is VARCHAR NOT NULL, as is title, and author. year is INTEGER. isbn numbers have a letter at the end, so what is valid input syntax?