Database
-
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})')
-
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})')
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
-
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})')
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.