def save_to_database(number, nome, message): try: conectar = mysql.connector.connect( host='localhost', database='db', user='root', password='***', auth_plugin='mysql_native_password' ) cursor = conectar.cursor() cursor.execute(""" CREATE TABLE usuario ( id INT AUTO_INCREMENT PRIMARY KEY, nome VARCHAR(50), numero VARCHAR(25) """) cursor.execute(""" CREATE TABLE mensagens ( id INT AUTO_INCREMENT PRIMARY KEY, conteudo TEXT, data VARCHAR(20), user_id BIGINT, FOREIGN KEY (user_id) REFERENCES usuario(id) """) query = f"INSERT INTO usuario (nome, numero) VALUES ({nome}, {number})" query2=f"INSERT INTO mensagens (conteudo, data) VALUES ({message}, {DATA})"
1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ” at line 4
I don’t know where’s the line 4 to solve this, but i think the problem is the FOREIGN KEY, cause I have no idea how to create this.
My table is not created atm.
2