Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
No such column id
#1
I found a tutorial where you can input a movie in the terminal and it prints out on screen. It gets the information from IMDB. That part works fine. But then I decided I wanted to import that information to a SQLite database. When I run my program the table is made but it will not populate due to errors. One error is "no such column: id, so I deleted that just to see what would happen. It just goes to the next one and say "no such column: title.

Here is the code to print to screen that works:
import imdb
import sqlite3

hr=imdb.IMDb()
movie_name=input("Enter the movie name : ")
movies=hr.search_movie(str(movie_name))
index=movies[0].getID()
movie=hr.get_movie(index)
title=movie['title']
year=movie['year']
cast=movie['cast']
rating=movie['rating']
plot=movie['plot']
list_of_cast=',' .join(map(str,cast))
print("title",title)
print("year of release: ",year)
print("full cast : ",list_of_cast)
print("rating: ",rating)
print("plot: ",plot)
print(movie.asXML())
I added the following for the SQLite database:

import sqlite3
from sqlite3 import Error

conn = sqlite3.connect('movies.db')
c = conn.cursor()
print ("Opened database successfully");

conn.execute('''CREATE TABLE IF NOT EXISTS data
         (ID INT PRIMARY KEY     NOT NULL,
         title           TEXT    NOT NULL,
         year_of_release INT     NOT NULL,
         full_cast       TEXT    NOT NULL,
         plot            TEXT);''')
print("Table created successfully");

conn.execute("INSERT INTO data (id, title, year_of_release, full_cast, plot) \
      VALUES (id, title, year_of_release, full_cast, plot)");



conn.commit()
print("Records created successfully");
conn.close()

conn.close()
This is the traceback:

Error:
Traceback (most recent call last): File "C:/Users/name/Documents/Python Projects/ImportIMDB/importimdb.py", line 38, in <module> VALUES (id, title, year_of_release, full_cast, plot)"); sqlite3.OperationalError: no such column: id Process finished with exit code 1
Thank you for any help that can be provided.
Reply
#2
You get index from IMDB, but then try to post id. From what I see, you do not assign a value to id.

I have not worked with SQLite, but since your values are all within the quotation marks, how will SQLite get access to the actual variables?
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020