30 lines
1.4 KiB
Python
30 lines
1.4 KiB
Python
from django.http import HttpResponse
|
|
from django.db import connection
|
|
|
|
def fix_db_view(request):
|
|
log = []
|
|
with connection.cursor() as cursor:
|
|
# 1. Check/Add is_service to core_product
|
|
try:
|
|
cursor.execute("SELECT is_service FROM core_product LIMIT 1")
|
|
log.append("SUCCESS: is_service already exists in core_product.")
|
|
except Exception:
|
|
try:
|
|
# Try MySQL syntax first
|
|
cursor.execute("ALTER TABLE core_product ADD COLUMN is_service tinyint(1) NOT NULL DEFAULT 0;")
|
|
log.append("FIXED: Added is_service column to core_product.")
|
|
except Exception as e:
|
|
log.append(f"ERROR adding is_service: {e}")
|
|
|
|
# 2. Check/Add is_active to core_paymentmethod
|
|
try:
|
|
cursor.execute("SELECT is_active FROM core_paymentmethod LIMIT 1")
|
|
log.append("SUCCESS: is_active already exists in core_paymentmethod.")
|
|
except Exception:
|
|
try:
|
|
cursor.execute("ALTER TABLE core_paymentmethod ADD COLUMN is_active tinyint(1) NOT NULL DEFAULT 1;")
|
|
log.append("FIXED: Added is_active column to core_paymentmethod.")
|
|
except Exception as e:
|
|
log.append(f"ERROR adding is_active: {e}")
|
|
|
|
return HttpResponse("<br>".join(log) + "<br><br><a href='/'>Go to Dashboard</a>") |