sqlite3.ERROR:表库存没有名为car\U make的列。当数据库有列时

2024-09-27 07:21:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在犯错误

Traceback (most recent call last):
  File "C:\Users\max\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 1705, in __call__
    return self.func(*args)
  File "G:\computing project\add to db.py", line 114, in get_items
    C.execute(sql ,vari)
sqlite3.OperationalError: table inventory has no column named car_make

尝试将值插入从tkinter获取的MyDatabase时

我曾尝试更改列的名称,以查看这是否可以解决问题。没有任何更改,我正在使用db browser编辑我的数据库

from tkinter import* 
import sqlite3
conn = sqlite3.connect("G:\computing project\database of cars.db")
C = conn.cursor()
import tkinter.messagebox


 def get_items(self,*args,**kwargs):  #this function gets the items from the entry boxes

        self.carmake= self.carmake_e.get()
        self.carmodel= self.carmodel_e.get()
        self.regi= self.regi_e.get()
        self.colour= self.colour_e.get()
        self.cost= self.cost_e.get()
        self.tcost= self.tcost_e.get()
        self.sellprice= self.sellprice_e.get()
        self.assumedprofit= self.assumedprofit_e.get()

        self.assumedprofit= float(self.sellprice)- float(self.tcost)


        if self.carmake == '' or self.carmodel == '' == self.colour == '':
            print ("WRONG")
            tkinter.messagebox.showinfo("error","please enter values for car make, model and colour")

        else:
            print("solid m8 ")
            sql = "INSERT INTO inventory(car_make,car_model,registration_plate,colour,cost,total_cost,selling_price,assumed_profit) VALUES (?,?,?,?,?,?,?)"
            vari=(self.carmake,self.carmodel,self.regi,self.colour,self.cost,self.tcost,self.sellprice,self.assumedprofit)
            C.execute(sql ,vari)
               # C.execute(sql(self.name,self.carmake,self.carmodel,self.regi,self.colour,self.cost,self.tcost,self.sellprice,self.assumedprofit))
            conn.commit()
            tkinter.messagebox.showinfo("success","succesfully added to databse")

Tags: selfdbsqlgettkinteritemscarcost

热门问题