#!/usr/bin/env python
"""
Fix missing Django tables by running migrations
"""
import os
import django

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

from django.core.management import call_command

print("=" * 80)
print("FIXING MISSING DJANGO TABLES")
print("=" * 80)

print("\nRunning migrations to create missing tables...")
print("This will create django_session and other Django system tables.\n")

try:
    # Run migrations
    call_command('migrate', verbosity=2)
    
    print("\n" + "=" * 80)
    print("✓ SUCCESS - All Django tables have been created!")
    print("=" * 80)
    print("\nYou can now login to the system.")
    
except Exception as e:
    print("\n" + "=" * 80)
    print("✗ ERROR")
    print("=" * 80)
    print(f"Error: {str(e)}")
    print("\nTry running manually:")
    print("  python manage.py migrate")
