Reputation: 1999
I'm pretty new to databases.
How can we remove a pandas dataframe from a sqlite database using flask_sqlalchmey
?
I added a dataframe to the database using df.to_sql
. But how would I remove it?
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
import pandas as pd
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'
db = SQLAlchemy(app)
df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
df.to_sql(name='my_table', con=db.engine)
The only thing I found was this question: Cannot drop table in pandas to_sql using SQLAlchemy But it does not help me or I don't understand it.
Any help appreciated!
Upvotes: 0
Views: 764
Reputation: 370
If you only want to drop my_table
table, you can use
db.engine.execute('DROP TABLE IF EXISTS my_table;')
Upvotes: 1