diff --git a/db/migrate/20240206085539_add_not_null_constraint_to_notes_noteable_type.rb b/db/migrate/20240206085539_add_not_null_constraint_to_notes_noteable_type.rb
new file mode 100644
index 0000000000000000000000000000000000000000..6f1cf9c61f565ad03aa241cbbf72ce2d79fa9a80
--- /dev/null
+++ b/db/migrate/20240206085539_add_not_null_constraint_to_notes_noteable_type.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+class AddNotNullConstraintToNotesNoteableType < Gitlab::Database::Migration[2.2]
+  disable_ddl_transaction!
+  milestone '16.9'
+
+  def up
+    add_not_null_constraint :notes, :noteable_type, validate: false
+  end
+
+  def down
+    remove_not_null_constraint :notes, :noteable_type
+  end
+end
diff --git a/db/post_migrate/20240206093635_add_index_to_notes_where_noteable_type_is_null_async.rb b/db/post_migrate/20240206093635_add_index_to_notes_where_noteable_type_is_null_async.rb
new file mode 100644
index 0000000000000000000000000000000000000000..dcf8e7de7a1eecc70c969369f3b8aa47825fbdc6
--- /dev/null
+++ b/db/post_migrate/20240206093635_add_index_to_notes_where_noteable_type_is_null_async.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class AddIndexToNotesWhereNoteableTypeIsNullAsync < Gitlab::Database::Migration[2.2]
+  milestone '16.9'
+
+  TABLE_NAME = :notes
+  INDEX_NAME = 'temp_index_on_notes_with_null_noteable_type'
+
+  def up
+    prepare_async_index TABLE_NAME, :id, where: "noteable_type IS NULL", name: INDEX_NAME
+  end
+
+  def down
+    unprepare_async_index TABLE_NAME, INDEX_NAME
+  end
+end
diff --git a/db/schema_migrations/20240206085539 b/db/schema_migrations/20240206085539
new file mode 100644
index 0000000000000000000000000000000000000000..73e89af4edeb03229e42907a3d69bae2f45a6d78
--- /dev/null
+++ b/db/schema_migrations/20240206085539
@@ -0,0 +1 @@
+e99c70a43d8171f44f4e7b0350053179db73d8b7908173381edff65b7095c844
\ No newline at end of file
diff --git a/db/schema_migrations/20240206093635 b/db/schema_migrations/20240206093635
new file mode 100644
index 0000000000000000000000000000000000000000..f94830bdefd8071eca533a3bf6d60a9dc080c6b2
--- /dev/null
+++ b/db/schema_migrations/20240206093635
@@ -0,0 +1 @@
+f5339eae21e720545dc09ede462bcdadb20a278a66134c3fe3cf4fa65d2a0a43
\ No newline at end of file
diff --git a/db/structure.sql b/db/structure.sql
index eca1ac35b7d53145b9cd2b000e758c577b88806b..c4a577cefa4a28703333eb66f862f62d9ce18b74 100644
--- a/db/structure.sql
+++ b/db/structure.sql
@@ -29219,6 +29219,9 @@ ALTER TABLE ONLY chat_names
 ALTER TABLE ONLY chat_teams
     ADD CONSTRAINT chat_teams_pkey PRIMARY KEY (id);
 
+ALTER TABLE notes
+    ADD CONSTRAINT check_1244cbd7d0 CHECK ((noteable_type IS NOT NULL)) NOT VALID;
+
 ALTER TABLE workspaces
     ADD CONSTRAINT check_2a89035b04 CHECK ((personal_access_token_id IS NOT NULL)) NOT VALID;
 
diff --git a/spec/lib/gitlab/markdown_cache/active_record/extension_spec.rb b/spec/lib/gitlab/markdown_cache/active_record/extension_spec.rb
index e33c60ef5926d8ae2d6e0c5b463c1153ef68159f..31c9829dfd0e5458e8469c3863cd58c54456582d 100644
--- a/spec/lib/gitlab/markdown_cache/active_record/extension_spec.rb
+++ b/spec/lib/gitlab/markdown_cache/active_record/extension_spec.rb
@@ -229,6 +229,7 @@
 
     before do
       thing.note = "hello world"
+      thing.noteable_type = "Issue"
     end
 
     it 'calls store_mentions!' do