#!/usr/bin/env python3
"""
Check actual table structures to fix foreign key constraint issues
"""

import os
import sys
import django

# Setup Django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'branch_system.settings')
django.setup()

from django.db import connection

def get_table_structure(table_name):
    """Get detailed table structure including column types"""
    with connection.cursor() as cursor:
        cursor.execute(f"DESCRIBE {table_name}")
        return cursor.fetchall()

def get_create_table_statement(table_name):
    """Get the CREATE TABLE statement for a table"""
    with connection.cursor() as cursor:
        cursor.execute(f"SHOW CREATE TABLE {table_name}")
        return cursor.fetchone()[1]

def main():
    print("=== LOANS TABLE STRUCTURE ===")
    loans_structure = get_table_structure('loans')
    for col in loans_structure:
        print(f"{col[0]}: {col[1]} {col[2]} {col[3]} {col[4]} {col[5]}")
    
    print("\n=== LOANS TABLE CREATE STATEMENT ===")
    loans_create = get_create_table_statement('loans')
    print(loans_create)
    
    print("\n=== LOAN_APPLICATIONS TABLE STRUCTURE ===")
    loan_apps_structure = get_table_structure('loan_applications')
    for col in loan_apps_structure:
        print(f"{col[0]}: {col[1]} {col[2]} {col[3]} {col[4]} {col[5]}")

if __name__ == "__main__":
    main()
