from django.http import HttpResponse
from django.core.management import call_command
import io

def fix_db_view(request):
    out = io.StringIO()
    try:
        call_command('migrate', 'core', stdout=out)
        return HttpResponse(f"SUCCESS: Database updated.<br><pre>{out.getvalue()}</pre><br><a href='/'>Go Home</a>")
    except Exception as e:
        return HttpResponse(f"ERROR: {e}<br><pre>{out.getvalue()}</pre>")