Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Python
  4. Database

Database

Scheduled Pinned Locked Moved Python
databasepythonsqlitehelpquestion
3 Posts 3 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    skmsjh
    wrote on last edited by
    #1

    I would like to request assistance with my code, where when inserting a table into the database from Python, the system replies with an error that says that the table is not nonexistent. However, the table is there. Cafeteria.py import sqlite3 from Chef_staff import * conn = sqlite3.connect('Chef__Order.db') curs = conn.cursor() MembersID = {'Aria': 'ID001', 'Barston': 'ID002', 'CJ': 'ID003', 'Damarsh': 'ID004', 'Elaine': 'ID005'} MembersFeedback = {'Aria': 0, 'Barston': 0, 'CJ': 0, 'Damarsh': 0, 'Elaine': 0} MembersOrder = {'Aria': 0, 'Barston': 0, 'CJ': 0, 'Damarsh': 0, 'Elaine': 0} Food = {'Burger': 5.00, 'Pancakes': 2.00, 'Sandwiches': 2.50, 'Steak': 10.00, 'Fries': 1.50, 'Tea': 0.50, 'Coffee': 0.75} FoodRating = {'Burger': 0, 'Pancakes': 0, 'Sandwiches': 0, 'Steak': 0, 'Fries': 0, 'Tea': 0, 'Coffee': 0} order_no = 0 burger_rate = 0 pancake_rate = 0 sandwich_rate = 0 steak_rate = 0 fries_rate = 0 tea_rate = 0 coffee_rate = 0 accumalated_b = 0 accumalated_p = 0 accumalated_sw = 0 accumalated_st = 0 accumalated_f = 0 accumalated_t = 0 accumalated_c = 0 while True: order_option = False login = input('Please enter your member username: ') for i in MembersID: if login == i: while order_option == False: price = 0 order_no =+ 1 order = int(input('Please select which food you would like to order\n1. Burger\n2. Pancakes\n3. Sandwiches\n4. Steak\n5. Fries\n6. Tea\n7. Coffee\n')) if order == 1: amount_order = int(input('How many burgers would you like to order?\n')) MembersOrder[i] += amount_order print(f'You have ordered {amount_order} Burger, {login}') price = Food['Burger'] * amount_order curs.execute(f'INSERT INTO Progression (OrderNo, ID, Food, Quantity, Price) VALUES ({order_no},{MembersID[i]},"Burger",{amount_order},{price})') elif order == 2: amount_order = int(input('How many pancake would you like to order?\n')) MembersOrder[i] += amount_order print(f'You have ordered {amount_order} Pancakes, {login}') price = Food['Pancakes'] * amount_order curs.execute(f'INSERT INTO Progression (OrderNo, ID, Food, Quantity, Price) VALUES ({order_no},{MembersID[i]},"Pancakes",{amount_order},{price})')

    R A 2 Replies Last reply
    0
    • S skmsjh

      I would like to request assistance with my code, where when inserting a table into the database from Python, the system replies with an error that says that the table is not nonexistent. However, the table is there. Cafeteria.py import sqlite3 from Chef_staff import * conn = sqlite3.connect('Chef__Order.db') curs = conn.cursor() MembersID = {'Aria': 'ID001', 'Barston': 'ID002', 'CJ': 'ID003', 'Damarsh': 'ID004', 'Elaine': 'ID005'} MembersFeedback = {'Aria': 0, 'Barston': 0, 'CJ': 0, 'Damarsh': 0, 'Elaine': 0} MembersOrder = {'Aria': 0, 'Barston': 0, 'CJ': 0, 'Damarsh': 0, 'Elaine': 0} Food = {'Burger': 5.00, 'Pancakes': 2.00, 'Sandwiches': 2.50, 'Steak': 10.00, 'Fries': 1.50, 'Tea': 0.50, 'Coffee': 0.75} FoodRating = {'Burger': 0, 'Pancakes': 0, 'Sandwiches': 0, 'Steak': 0, 'Fries': 0, 'Tea': 0, 'Coffee': 0} order_no = 0 burger_rate = 0 pancake_rate = 0 sandwich_rate = 0 steak_rate = 0 fries_rate = 0 tea_rate = 0 coffee_rate = 0 accumalated_b = 0 accumalated_p = 0 accumalated_sw = 0 accumalated_st = 0 accumalated_f = 0 accumalated_t = 0 accumalated_c = 0 while True: order_option = False login = input('Please enter your member username: ') for i in MembersID: if login == i: while order_option == False: price = 0 order_no =+ 1 order = int(input('Please select which food you would like to order\n1. Burger\n2. Pancakes\n3. Sandwiches\n4. Steak\n5. Fries\n6. Tea\n7. Coffee\n')) if order == 1: amount_order = int(input('How many burgers would you like to order?\n')) MembersOrder[i] += amount_order print(f'You have ordered {amount_order} Burger, {login}') price = Food['Burger'] * amount_order curs.execute(f'INSERT INTO Progression (OrderNo, ID, Food, Quantity, Price) VALUES ({order_no},{MembersID[i]},"Burger",{amount_order},{price})') elif order == 2: amount_order = int(input('How many pancake would you like to order?\n')) MembersOrder[i] += amount_order print(f'You have ordered {amount_order} Pancakes, {login}') price = Food['Pancakes'] * amount_order curs.execute(f'INSERT INTO Progression (OrderNo, ID, Food, Quantity, Price) VALUES ({order_no},{MembersID[i]},"Pancakes",{amount_order},{price})')

      R Offline
      R Offline
      Richard Deeming
      wrote on last edited by
      #2

      skmsjh wrote:

      the table is not nonexistent

      Assuming that double-negative is a mistake, then the error is telling you that the table does not exist.

      skmsjh wrote:

      However, the table is there.

      You say the table is there; the error message says the table is not there. Guess which statement we're going to believe? Start by triple-checking which database you're connecting to. Based on the code, it looks like you're connecting to a file-based database in the current working directory, which is usually the same directory as your code. You have almost certainly added the tables to a different copy of that database.


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      1 Reply Last reply
      0
      • S skmsjh

        I would like to request assistance with my code, where when inserting a table into the database from Python, the system replies with an error that says that the table is not nonexistent. However, the table is there. Cafeteria.py import sqlite3 from Chef_staff import * conn = sqlite3.connect('Chef__Order.db') curs = conn.cursor() MembersID = {'Aria': 'ID001', 'Barston': 'ID002', 'CJ': 'ID003', 'Damarsh': 'ID004', 'Elaine': 'ID005'} MembersFeedback = {'Aria': 0, 'Barston': 0, 'CJ': 0, 'Damarsh': 0, 'Elaine': 0} MembersOrder = {'Aria': 0, 'Barston': 0, 'CJ': 0, 'Damarsh': 0, 'Elaine': 0} Food = {'Burger': 5.00, 'Pancakes': 2.00, 'Sandwiches': 2.50, 'Steak': 10.00, 'Fries': 1.50, 'Tea': 0.50, 'Coffee': 0.75} FoodRating = {'Burger': 0, 'Pancakes': 0, 'Sandwiches': 0, 'Steak': 0, 'Fries': 0, 'Tea': 0, 'Coffee': 0} order_no = 0 burger_rate = 0 pancake_rate = 0 sandwich_rate = 0 steak_rate = 0 fries_rate = 0 tea_rate = 0 coffee_rate = 0 accumalated_b = 0 accumalated_p = 0 accumalated_sw = 0 accumalated_st = 0 accumalated_f = 0 accumalated_t = 0 accumalated_c = 0 while True: order_option = False login = input('Please enter your member username: ') for i in MembersID: if login == i: while order_option == False: price = 0 order_no =+ 1 order = int(input('Please select which food you would like to order\n1. Burger\n2. Pancakes\n3. Sandwiches\n4. Steak\n5. Fries\n6. Tea\n7. Coffee\n')) if order == 1: amount_order = int(input('How many burgers would you like to order?\n')) MembersOrder[i] += amount_order print(f'You have ordered {amount_order} Burger, {login}') price = Food['Burger'] * amount_order curs.execute(f'INSERT INTO Progression (OrderNo, ID, Food, Quantity, Price) VALUES ({order_no},{MembersID[i]},"Burger",{amount_order},{price})') elif order == 2: amount_order = int(input('How many pancake would you like to order?\n')) MembersOrder[i] += amount_order print(f'You have ordered {amount_order} Pancakes, {login}') price = Food['Pancakes'] * amount_order curs.execute(f'INSERT INTO Progression (OrderNo, ID, Food, Quantity, Price) VALUES ({order_no},{MembersID[i]},"Pancakes",{amount_order},{price})')

        A Offline
        A Offline
        Akrash Nadeem
        wrote on last edited by
        #3

        I recommend to create database tables after you connect to the database. put this code at after creating conn variable to avoid tables does not exists issue.

        conn = sqlite3.connect('Chef__Order.db')
        conn.execute("""CREATE TABLE IF NOT EXISTS "Chef" ( "ChefID" TEXT NOT NULL, "Chefs" TEXT NOT NULL, "Meals cooked No." INTEGER, PRIMARY KEY("ChefID","Chefs") )""")
        conn.execute("""CREATE TABLE IF NOT EXISTS "Food" ("FoodID" INTEGER, "Food names" TEXT, "Ratings" INTEGER, "Price" INTEGER, PRIMARY KEY("Price", "Food names", "FoodID"))""")
        conn.execute("""CREATE TABLE IF NOT EXISTS "Members" ("ID" TEXT NOT NULL, "Names" TEXT, "Feedback" INTEGER, PRIMARY KEY("ID","Names"))""")
        conn.execute("""CREATE TABLE IF NOT EXISTS "Progression" ("OrderNo" INTEGER, "ID" TEXT, "Food" TEXT, "Quantity" INTEGER, "Price" REAL, "Progress" TEXT, FOREIGN KEY("ID") REFERENCES "Members"("ID"))""")

        This code will create table if it already does not exists and if it already exists it will not through any error and the program will run just fine.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups