Hi, just joined this website as you guys seemed like the perfect people to ask for help, I'm creating a database system using python for car rental with tables customers,cars,and rentals. The customer table is fine but on my add_cars() function which adds a new car it is showing some error unlike the customer table. I've attached the customer table code which works and the car one which doesn't work :(
def initialise():
MyConnection = connect ('rockitrally.db')
MyCursor = MyConnection.cursor()
MyCursor.execute('''CREATE TABLE Customers
(CustomerID INTEGER PRIMARY KEY,
Forename TEXT,
Surname TEXT,
DOB TEXT,
Address TEXT,
Phone TEXT,
Email TEXT)''')
MyCursor.execute('''CREATE TABLE Cars
(CarID INTEGER PRIMARY KEY,
Make TEXT,
Model TEXT,
Miles INTEGER,
Price REAL,
Number_Rentals TEXT)''')
MyCursor.execute('''CREATE TABLE Rentals
(RentalID INTEGER PRIMARY KEY,
CustomerID INTEGER,
CarID INTEGER,
Forename TEXT,
Surname TEXT,
Make TEXT,
Model TEXT,
Price REAL)''')
def add_customers():
MyConnection = connect('rockitrally.db')
MyCursor = MyConnection.cursor()
Forename=input("Enter the customer's forename: ")
Surname=input("Enter the customer's surname: ")
DOB=input("Enter the customer's DOB: ")
Address=input("Enter the customer's address: ")
Phone=input("Enter the customer's phone no: ")
Email=input("Enter the customer's email: ")
MyCursor.execute("INSERT INTO Customers VALUES (NULL,?,?,?,?,?,?)",(Forename,Surname,DOB,Address,Phone,Email))
MyConnection.commit()
MyCursor.close()
MyConnection.close()
def add_cars():
MyConnection = connect('rockitrally.db')
MyCursor = MyConnection.cursor()
Make=input("Enter the car's make: ")
Model=input("Enter the car's model: ")
Miles=int(input("Enter the car's mileage: "))
Price=float(input("Enter the car's rental price: "))
Number_Rentals=input("Enter how many times the car has been rented: ")
MyCursor.execute("INSERT INTO Cars VALUES (NULL,?,?,?,?,?)",(Make,Model,Miles,Price,Number_Rentals))
MyConnection.commit()
MyCursor.close()
MyConnection.close()
MyCursor.execute("INSERT INTO Cars VALUES (NULL,?,?,?,?,?)",(Make,Model,Miles,Price,Number_Rentals))
sqlite3.OperationalError: table Cars has 4 columns but 6 values were supplied
The ID for customers and cars is automatically generated
Please help :(