1

I am getting this error: DatabaseError: Execution failed on sql 'SELECT name FROM sqlite_master WHERE type='table' AND name=?;': Not all parameters were used in the SQL statement. when trying to convert my dataframe to sql

My connection variable:

con = mysql.connector.connect(
  host="****",
  port="****",
  database="*****",
  user="*****",
  password="*****"
)

My try to convert it to sql:

df.to_sql('menageiro2',con)

Note: I am using:

  • import pandas as pd
  • import sqlalchemy
  • import mysql.connector
4
  • 2
    You leaked your password so make sure you change that. The error means that the sql query expects input for the name bind variable. Can you post a self-contained example to demonstrate the issue? Otherwise I cannot debug this for you. Others may be able to of course. Commented Feb 27, 2021 at 3:03
  • DUDE THANKS A LOT LMAOF. I did not notice that Commented Feb 27, 2021 at 3:08
  • You mean a picture of the dataframe? Commented Feb 27, 2021 at 3:11
  • stackoverflow.com/help/minimal-reproducible-example Pictures are better than nothing but that means if I try to run your code, I have to transcribe it to text. It's better if you post an actual minimal example of a program that exhibit the issue. That said, see my answer below (my current best guess). Commented Feb 27, 2021 at 3:13

1 Answer 1

3

The reference says con: sqlalchemy.engine.(Engine or Connection) or sqlite3.Connection. You appear to be passing in a mysql connection instead of a SQLAlchamy engine (that you connected to MySQL):

con = sqlalchemy.create_engine(
'mysql+mysqlconnector://<user>:<password>@<host>:<port>/<default_db>...')
Sign up to request clarification or add additional context in comments.

3 Comments

Do I have to take off "< >"?
Thanks a lot man! That was the problem. Do you know why do I have to use SQLAlchemy engine?
That was the choice of whoever wrote the pandas to_sql() function. SQLAlchamy probably works as comparability layer, so they can support more database without having to write a bunch per database specific code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.