Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

265
Views
No such table error when replacing a table through SQLalchemy?

I am using SQLalchemy and the pandas method pd.to_sql(if_exists="replace") to insert data in to a table in PostgreSQL.

Now, if the table doesn't exist, then everything works ok.

But, if the table already exists (I know it exists since I can see it in pgAdmin), I get the following error: sqlalchemy.exc.NoSuchTableError:

SQLalchemy is trying to drop this table to replace it with the new one, but it can't find the table for some reason?

Here is a snippet of the code:

ENGINE = create_engine(...)

with ENGINE.begin() as con:
   df.to_sql("table_name", con=con, index=False, if_exists="replace")

This throws the above error? I have tried specifying the schema but this also throws the same error.

Why isn't SQLalchemy finding the table even though it's there?

EDIT: If I remove the if_exists="replace", I then get the error: ValueError: Table tablename already exists.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!