Insert INTO mysql and python error

Asked

Viewed 45 times

-1

When I try to make an INSERT INTO in my SQL code, it gives the same error

mysql.connector.errors.DataError: 1292 (22007): Incorrect date value: '1998' for column 'validade' at row 1

This is my CREATE TABLE command

CREATE TABLE IF NOT EXISTS produtos(
        cod INT NOT NULL,
        nome_produto VARCHAR(45) NOT NULL,
        marca VARCHAR(45) NOT NULL,
        validade DATE NOT NULL,
        qtd_estoque INT NOT NULL,
        primary key (cod)

And this is my INSERT INTO

INSERT INTO produtos 
    (nome_produto, marca, preco, validade, qtd_estoque)
    values
    ('Brahma Chopp 269ml', 'Brahma', 2.39, 2021-08-15, 600),
    ('Brahma Chopp 350ml', 'Brahma', 2.59, 2021-08-15, 600),
    ('Brahma Extra Lager 350ml', 'Brahma', 2.79, 2021-08-15, 500),
    ('Skol 269ml', 'Skol', 2.29, 2021-08-15, 500),
    ('Skol 473ml', 'Skol', 3.99, 2021-08-15, 500),
    ('Skol Puro Malte 350ml', 'Skol', 2.59, 2021-08-15, 400),
    ('Budweiser 350ml', 'Budweiser', 3.29, 2021-11-11, 650),
    ('Budweiser 269ml', 'Budweiser', 2.89, 2021-11-11, 650),
    ('Budweiser 430ml', 'Budweiser', 3.99, 2021-11-11, 650),
    ('Stela Artrois 330ml','Stela Artrois', 4.49, 2021-11-11, 300),
    ('Becks 330ml','Becks', 5.99, 2021-11-11, 300),
    ('Corona Extra 330ml', 'Corona', 5.99, 2021-11-11, 350),
    ('Coronita 210ml', 'Corona', 3.99, 2021-11-11, 250),
    ('Colorado Cauim 600ml', 'Colorado', 12.99, 2021-11-11, 200),
    ('Colorado Vixnu 600ml', 'Colorado', 15.99, 2021-11-11, 200),
    ('Colorado Demoiselle 600ml', 'Colorado', 12.99, 2021-11-11, 200),
    ('Vodka Smirnoff 998ml', 'Smirnoff', 38.99, 2022-11-11, 700),
    ('Vodka Orloff 1L', 'Orloff', 26.90, 2022-11-11, 400),
    ('Vodka Absolute Elyx 750ml', 'Absolute', 169.99, 2022-11-11, 300),
    ('Vodka Absolute Original 750ml', 'Absolute', 80.90, 2022-11-11, 450),
    
    ('Whisky White Horse 1L', 'White Horse', 74.90, 2022-11-11, 300),
    ('Whisky Red Label 1L', 'Jonhie Walker', 98.90, 2022-11-11, 300),
    ('Whisky Green Label 1L', 'Jonhie Walker', 98.90, 2022-11-11, 300),

    ('Cachaça do Barril 500ml', 'Do Barril', 3.99, 2022-11-11, 200),
    ('Cachaça 51 1L', '51', 9.99, 2022-11-11, 200),

    ('Gin Tanqueray 750ml', 'Tanqueray', 126.90, 2022-11-11, 700),
    ('Gin Bombay 750ml', 'Bombay Saphire', 100.90, 2022-11-11, 700),
    ('Gin Gordons London Dry 700ml', 'Gordons', 85.90, 2022-11-11, 400),

    ('Catuaba Selvagem 1L', 'Selvagem', 13.90, 2023-11-11, 400),
    ('Coquetel Ousadia 500ml', 'Ousadia', 4.99, 2023-11-11, 400),
    ('Corote 500ml', 'Missiato', 3.99, 2023-11-11, 600),

    ('Licor Campari 900ml', 'Campari', 37.90, 2023-11-11, 400),
    ('Aperol 750ml', 'Campari', 49.90, 2023-11-11, 400),

    ('Tequila Jose Cuervo Gold Edition', 'Jose Cuervo', 129.99, 2021-11-11, 400),

    ('Vinho Tinto Cantina da Serra 800ml', 'Cantina da Serra', 17.50, 2023-11-11, 200),
    ('Vinho Tinto Pérgola 1L', 'Pérgola', 22.99, 2023-11-11, 200),

    ('Red Bull Energy Drink 250ml', 'Red Bull', 6.88, 2022-11-11, 800),
    ('Red Bull Tropical Energy Drink 250ml', 'Red Bull', 8.99, 2022-11-11, 800);

1 answer

2

You need to quote the date, it treats the number you are sending as a subtraction. Ex:

INSERT INTO produtos 
    (nome_produto, marca, preco, validade, qtd_estoque)
    values
    ('Brahma Chopp 269ml', 'Brahma', 2.39, '2021-08-15', 600);
  • Thanks! It worked, it was a mistake beast kkkkk

Browser other questions tagged

You are not signed in. Login or sign up in order to post.