DEV Community

G luck
G luck

Posted on

Answer: Is it possible to create foreign keys with pandas to_sql

While the to_sql method in pandas doesn't directly handle foreign key constraints, you can still create them after loading data into your SQL database. If you're using SQLAlchemy, you can follow these steps:

  1. Write your DataFrames to SQL tables using to_sql.
  2. Execute an ALTER TABLE SQL statement to define…

Top comments (0)