# ONE-LINER TO FIX AUTO_INCREMENT ISSUE
# Run this in your cPanel terminal/SSH

cd /home/acbptxvs/public_html/branchbusinessadvance.co.ke && python3 -c "
import os, django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'branch_system.settings')
django.setup()
from django.db import connection
with connection.cursor() as cursor:
    # Check current auto_increment value
    cursor.execute('SHOW TABLE STATUS LIKE \"portfolio_assignments\"')
    result = cursor.fetchone()
    if result:
        auto_increment = result[10]  # Auto_increment column
        print(f'Current auto_increment value: {auto_increment}')
        
        # If it's 0 or NULL, set it to 1
        if auto_increment == 0 or auto_increment is None:
            cursor.execute('ALTER TABLE portfolio_assignments AUTO_INCREMENT = 1')
            print('Set auto_increment to 1')
        else:
            print('Auto_increment is already set correctly')
    else:
        print('Could not get table status')
" && echo "AUTO_INCREMENT FIXED!"
