Error importing course "Duplicate entry for key 'mdl_course_sections.mdl_coursect_cousec_uix'"

Error importing course "Duplicate entry for key 'mdl_course_sections.mdl_coursect_cousec_uix'"

ved Владислав Ванда -
Antal besvarelser: 2

Moodle 4.5.1 Build: 20250124 

I'm trying to copy a course via import and I get an error. I go to mdl_course_sections table in phpMyAdmin and I see that the import script creates a section from a subsection and this leads to the fact that the next section cannot be created because the unique index is already occupied. What is this and how to solve it?

Error
Duplicate entry '3236-4' for key 'mdl_course_sections.mdl_coursect_cousec_uix'
UPDATE mdl_course_sections SET section = ? WHERE id=?
-- line 1719 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->update_record_raw()
-- line 1865 of /backup/moodle2/restore_stepslib.php: call to mysqli_native_moodle_database->update_record()
-- line 1662 of /backup/moodle2/restore_stepslib.php: call to restore_section_structure_step->displace_delegated_sections_after()
-- line 137 of /backup/util/plan/restore_structure_step.class.php: call to restore_section_structure_step->process_section()
-- line 123 of /backup/util/helper/restore_structure_parser_processor.class.php: call to restore_structure_step->process()
-- line 178 of /backup/util/xml/parser/processors/grouped_parser_processor.class.php: call to restore_structure_parser_processor->dispatch_chunk()
-- line 111 of /backup/util/helper/restore_structure_parser_processor.class.php: call to grouped_parser_processor->postprocess_chunk()
-- line 148 of /backup/util/xml/parser/processors/simplified_parser_processor.class.php: call to restore_structure_parser_processor->postprocess_chunk()
-- line 92 of /backup/util/xml/parser/processors/progressive_parser_processor.class.php: call to simplified_parser_processor->process_chunk()
-- line 189 of /backup/util/xml/parser/progressive_parser.class.php: call to progressive_parser_processor->receive_chunk()
-- line 277 of /backup/util/xml/parser/progressive_parser.class.php: call to progressive_parser->publish()
-- line unknown of unknownfile: call to progressive_parser->end_tag()
-- line 178 of /backup/util/xml/parser/progressive_parser.class.php: call to xml_parse()
-- line 157 of /backup/util/xml/parser/progressive_parser.class.php: call to progressive_parser->parse()
-- line 110 of /backup/util/plan/restore_structure_step.class.php: call to progressive_parser->process()
-- line 199 of /backup/util/plan/base_task.class.php: call to restore_structure_step->execute()
-- line 122 of /backup/moodle2/restore_section_task.class.php: call to base_task->execute()
-- line 191 of /backup/util/plan/base_plan.class.php: call to restore_section_task->execute()
-- line 168 of /backup/util/plan/restore_plan.class.php: call to base_plan->execute()
-- line 411 of /backup/controller/restore_controller.class.php: call to restore_plan->execute()
-- line 200 of /backup/import.php: call to restore_controller->execute_plan()
[array (
0 => 4,
1 => '24294',
)]
Error code: dmlwriteexception

  • line 500 of /lib/dml/moodle_database.php: dml_write_exception thrown
  • line 293 of /lib/dml/moodle_read_slave_trait.php: call to moodle_database->query_end()
  • line 1686 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->query_end()
  • line 1719 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->update_record_raw()
  • line 1865 of /backup/moodle2/restore_stepslib.php: call to mysqli_native_moodle_database->update_record()
  • line 1662 of /backup/moodle2/restore_stepslib.php: call to restore_section_structure_step->displace_delegated_sections_after()
  • line 137 of /backup/util/plan/restore_structure_step.class.php: call to restore_section_structure_step->process_section()
  • line 123 of /backup/util/helper/restore_structure_parser_processor.class.php: call to restore_structure_step->process()
  • line 178 of /backup/util/xml/parser/processors/grouped_parser_processor.class.php: call to restore_structure_parser_processor->dispatch_chunk()
  • line 111 of /backup/util/helper/restore_structure_parser_processor.class.php: call to grouped_parser_processor->postprocess_chunk()
  • line 148 of /backup/util/xml/parser/processors/simplified_parser_processor.class.php: call to restore_structure_parser_processor->postprocess_chunk()
  • line 92 of /backup/util/xml/parser/processors/progressive_parser_processor.class.php: call to simplified_parser_processor->process_chunk()
  • line 189 of /backup/util/xml/parser/progressive_parser.class.php: call to progressive_parser_processor->receive_chunk()
  • line 277 of /backup/util/xml/parser/progressive_parser.class.php: call to progressive_parser->publish()
  • line ? of unknownfile: call to progressive_parser->end_tag()
  • line 178 of /backup/util/xml/parser/progressive_parser.class.php: call to xml_parse()
  • line 157 of /backup/util/xml/parser/progressive_parser.class.php: call to progressive_parser->parse()
  • line 110 of /backup/util/plan/restore_structure_step.class.php: call to progressive_parser->process()
  • line 199 of /backup/util/plan/base_task.class.php: call to restore_structure_step->execute()
  • line 122 of /backup/moodle2/restore_section_task.class.php: call to base_task->execute()
  • line 191 of /backup/util/plan/base_plan.class.php: call to restore_section_task->execute()
  • line 168 of /backup/util/plan/restore_plan.class.php: call to base_plan->execute()
  • line 411 of /backup/controller/restore_controller.class.php: call to restore_plan->execute()
  • line 200 of /backup/import.php: call to restore_controller->execute_plan()

Course structure

courseCourse structure 
course

mdl_course_sections of original course

origa

mdl_course_sections of copy

copy

mdl_course_sections table

mdl_course_sections

Gennemsnitsbedømmelse: -
I svar til Владислав Ванда

Error importing course "Duplicate entry for key 'mdl_course_sections.mdl_coursect_cousec_uix'"

ved Владислав Ванда -
I svar til Владислав Ванда

Error importing course "Duplicate entry for key 'mdl_course_sections.mdl_coursect_cousec_uix'"

ved Gareth Barnard -
Billede af Core developers Billede af Particularly helpful Moodlers Billede af Plugin developers
Dear Владислав,

I'm glad that you've solved it and thank you for replying with the solution.

Kind regards,

Gareth
Gennemsnitsbedømmelse:Useful (1)