why do i keep having an error can someone explain and help me with this

51 Views Asked by At

I'm trying to make a simple ticketing cinema and I'm copying this certain youtuber work for reference but I keep having an error and it says this (look at the image). I don't know what's the mismatch here since I already checked it multiple times and here's the code:

enter image description here

import sqlite3

def create_table():
    conn = sqlite3.connect('Reservation.db')
    cursor = conn.cursor()

    cursor.execute('''
        CREATE TABLE IF NOT EXISTS Tickets (
            ticket_id INTEGER PRIMARY KEY,
            movie_name TEXT,
            ticket_quantity INTEGER,
            ticket_price INTEGER
        )''')

    conn.commit()
    conn.close()
    
def insert_Tickets():
    conn = sqlite3.connect('Reservation.db')
    cursor = conn.cursor()

    Tickets_data = [
        ('T1', 'Movie1', 3, 50),
        ('T2', 'Movie2', 2, 40),
        ('T3', 'Movie3', 4, 60),
        ('T4', 'Movie4', 5, 60),
        ('T5', 'Movie5', 1, 65)
    ]

    cursor.executemany('INSERT OR REPLACE INTO Tickets (ticket_id, movie_name, ticket_quantity, ticket_price) VALUES (?, ?, ?, ?)', Tickets_data)

    conn.commit()
    conn.close()


def get_tickets():
    conn = sqlite3.connect('Reservation.db')
    cursor = conn.cursor()
    cursor.execute('SELECT * FROM Tickets')
    tickets = cursor.fetchall()
    conn.close()
    
    return tickets

def update_quantity(id,reserved_quantity):
    conn = sqlite3.connect('Reservation.db')
    cursor = conn.cursor()
    cursor.execute('UPDATE Tickets SET ticket_quantity = ticket_quantity - ? WHERE ticket_id = ?',(reserved_quantity,id))
    
    conn.commit()
    conn.close()
    
create_table()
insert_Tickets()
1

There are 1 best solutions below

0
On

If you add a column id for your primary key, it will work, because the primary key will be filled automatically. Change your create table command to:

cursor.execute('''
        CREATE TABLE IF NOT EXISTS Tickets (
            id INTEGER NOT NULL PRIMARY KEY,
            ticket_id Text,
            movie_name TEXT,
            ticket_quantity INTEGER,
            ticket_price INTEGER
        )''')