drop_tables.py 483 B

12345678910111213141516171819202122
  1. from app import create_app, db
  2. from sqlalchemy import text
  3. app = create_app()
  4. with app.app_context():
  5. # Disable foreign key checks
  6. db.session.execute(text('SET FOREIGN_KEY_CHECKS = 0'))
  7. # Reflect all tables
  8. db.reflect()
  9. # Drop all tables
  10. db.drop_all()
  11. # Recreate all tables
  12. db.create_all()
  13. # Enable foreign key checks
  14. db.session.execute(text('SET FOREIGN_KEY_CHECKS = 1'))
  15. print("All tables dropped and recreated.")