Fix exams foreign key constraint on lesson_id by using NULL instead of 0 for unit exams

This commit is contained in:
Hamza-Ayed
2026-09-03 16:46:17 +03:00
parent be4fe3dabf
commit 9624cfb4c8
2 changed files with 13 additions and 4 deletions
+2 -2
View File
@@ -436,11 +436,11 @@ class ExamController
if (!$examId) {
$examId = (int)Database::insert(
"INSERT INTO exams (uuid, course_id, lesson_id, creator_type, scope, title, passing_percentage, total_points, duration_minutes, is_mandatory, is_published)
VALUES (UUID(), 1, 0, 'ai_adaptive', 'unit_exam', 'اختبار الفهم الشامل: الوحدة الأولى — أنظمة المعادلات', 70.00, 100, 45, 1, 1)"
VALUES (UUID(), 1, NULL, 'ai_adaptive', 'unit_exam', 'اختبار الفهم الشامل: الوحدة الأولى — أنظمة المعادلات', 70.00, 100, 45, 1, 1)"
);
} else {
Database::query(
"UPDATE exams SET title = 'اختبار الفهم الشامل: الوحدة الأولى — أنظمة المعادلات', duration_minutes = 45, total_points = 100, passing_percentage = 70.00, scope = 'unit_exam', is_published = 1 WHERE id = ?",
"UPDATE exams SET title = 'اختبار الفهم الشامل: الوحدة الأولى — أنظمة المعادلات', duration_minutes = 45, total_points = 100, passing_percentage = 70.00, scope = 'unit_exam', lesson_id = NULL, is_published = 1 WHERE id = ?",
[$examId]
);
}