from loans.models import MpesaTransaction
from django.db import connection

# Get the actual table name from the model
table_name = MpesaTransaction._meta.db_table
print(f"MpesaTransaction table name: {table_name}")

# Check if table exists
with connection.cursor() as cursor:
    cursor.execute(f"SHOW TABLES LIKE '{table_name}';")
    result = cursor.fetchone()
    if result:
        print(f"✓ Table '{table_name}' exists")
        
        # Check columns
        cursor.execute(f"SHOW COLUMNS FROM {table_name};")
        columns = cursor.fetchall()
        print(f"\nColumns in {table_name}:")
        has_business_short_code = False
        for col in columns:
            col_name = col[0]
            if col_name == 'business_short_code':
                has_business_short_code = True
                print(f"  ✓ {col_name} - EXISTS")
            elif 'short' in col_name.lower() or 'business' in col_name.lower():
                print(f"  - {col_name}")
        
        if not has_business_short_code:
            print("\n✗ business_short_code column is MISSING")
        else:
            print("\n✓ business_short_code column exists")
    else:
        print(f"✗ Table '{table_name}' does NOT exist")
