Spaces:
Sleeping
Sleeping
File size: 872 Bytes
67c8aca | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | import os
from backend.db.database import engine
from backend.db import models
def reset_db():
print("Attempting to reset database...")
try:
# Drop all tables
models.Base.metadata.drop_all(bind=engine)
print("Dropped all tables.")
# Recreate all tables
models.Base.metadata.create_all(bind=engine)
print("Recreated all tables with new schema.")
# Alternatively, try to delete the file if it exists
db_path = "loan_system.db"
if os.path.exists(db_path):
try:
os.remove(db_path)
print(f"Deleted {db_path} file.")
except Exception as e:
print(f"Could not delete file (might be locked): {e}")
except Exception as e:
print(f"Error during reset: {e}")
if __name__ == "__main__":
reset_db()
|