-1

i have a problem with the importation of sql

import sqlite3
connection = sqlite3.connect('database.db')
with open('crea_posts.sql') as f:
    connection.executescript(f.read())
connection.commit()
connection.close()

debug

Traceback (most recent call last):
  File "C:\Users\Tamarrino\Desktop\flask app\init_db.py", line 4, in <module>
    connection.executescript(f.read())
sqlite3.OperationalError: 1 values for 2 columns

this is the crea_post.sql

DROP TABLE IF EXISTS posts;

CREATE TABLE posts (
    titolo TEXT,
    info TEXT
);

INSERT INTO posts (titolo, info) VALUES (
    'Lava la macchina',
    'Lava accuratamente la carrozzeria e gli interni'
);
INSERT INTO posts (titolo, info) VALUES (
    'Lava il frigo'
);
INSERT INTO posts (titolo, info) VALUES (
    'Porta la macchina dal meccanico'
    'Guasto al motore'
);
h0r53
  • 3,034
  • 2
  • 16
  • 25

1 Answers1

0

I think you are missing a comma in the last values of the insert. It should be

INSERT INTO posts (titolo, info) VALUES ( 'Porta la macchina dal meccanico', 'Guasto al motore' );
RMT
  • 105
  • 8