diff --git a/db/migrations/5.3.25_remove_bogus_folders_biest_4008.php b/db/migrations/5.3.25_remove_bogus_folders_biest_4008.php
new file mode 100644
index 0000000000000000000000000000000000000000..14fa348b239918d38b7afa9a93c2d7e109c6613a
--- /dev/null
+++ b/db/migrations/5.3.25_remove_bogus_folders_biest_4008.php
@@ -0,0 +1,18 @@
+<?php
+/**
+ * @see https://gitlab.studip.de/studip/studip/-/issues/4777
+ */
+return new class extends Migration
+{
+    public function description()
+    {
+        return 'Removes the invalid entries from folder table (see BIEST#4008)';
+    }
+
+    protected function up()
+    {
+        $query = "DELETE FROM `folders`
+                  WHERE `folder_type` IN ('course', 'user')";
+        DBManager::get()->exec($query);
+    }
+};