diff --git a/web/pgadmin/static/js/components/Buttons.jsx b/web/pgadmin/static/js/components/Buttons.jsx
index 27dabf998..f7ca5f7f8 100644
--- a/web/pgadmin/static/js/components/Buttons.jsx
+++ b/web/pgadmin/static/js/components/Buttons.jsx
@@ -92,6 +92,15 @@ const useStyles = makeStyles((theme)=>({
     '&.Mui-disabled': {
       border: 0,
     },
+  },
+  noBorderPrimary: {
+    color: theme.palette.primary.contrastText,
+    backgroundColor: theme.palette.primary.main,
+    '&:hover': {
+      color: theme.palette.primary.contrastText,
+      backgroundColor: theme.palette.primary.hoverMain,
+      borderColor: theme.palette.primary.hoverBorderColor,
+    },
   }
 }));
 
@@ -104,7 +113,7 @@ export const PrimaryButton = forwardRef((props, ref)=>{
     size = undefined;
     allClassName.push(classes.xsButton);
   }
-  noBorder && allClassName.push(classes.noBorder);
+  noBorder && allClassName.push(...[classes.noBorder, classes.noBorderPrimary]);
   const dataLabel = typeof(children) == 'string' ? children : undefined;
   return (
     <Button ref={ref} size={size} className={clsx(allClassName)} data-label={dataLabel} {...otherProps} variant="contained" color="primary">{children}</Button>
diff --git a/web/pgadmin/static/js/components/CodeMirror.jsx b/web/pgadmin/static/js/components/CodeMirror.jsx
index b0d496624..4141369d1 100644
--- a/web/pgadmin/static/js/components/CodeMirror.jsx
+++ b/web/pgadmin/static/js/components/CodeMirror.jsx
@@ -71,17 +71,21 @@ function parseString(string) {
 }
 
 function parseQuery(query, useRegex=false, matchCase=false) {
-  if (useRegex) {
-    query = new RegExp(query, matchCase ? 'g': 'gi');
-  } else {
-    query = parseString(query);
-    if(!matchCase) {
-      query = query.toLowerCase();
+  try {
+    if (useRegex) {
+      query = new RegExp(query, matchCase ? 'g': 'gi');
+    } else {
+      query = parseString(query);
+      if(!matchCase) {
+        query = query.toLowerCase();
+      }
     }
+    if (typeof query == 'string' ? query == '' : query.test(''))
+      query = /x^/;
+    return query;
+  } catch (error) {
+    return null;
   }
-  if (typeof query == 'string' ? query == '' : query.test(''))
-    query = /x^/;
-  return query;
 }
 
 function getRegexFinder(query) {
@@ -143,6 +147,8 @@ export function FindDialog({editor, show, replace, onClose}) {
   const search = ()=>{
     if(editor) {
       let query = parseQuery(findVal, useRegex, matchCase);
+      if(!query) return;
+
       searchCursor.current = editor.getSearchCursor(query, 0, !matchCase);
       if(findVal != '') {
         editor.removeOverlay(highlightsearch.current);
diff --git a/web/pgadmin/tools/erd/static/js/erd_tool/ERDCore.js b/web/pgadmin/tools/erd/static/js/erd_tool/ERDCore.js
index afcf30c3c..626f649cc 100644
--- a/web/pgadmin/tools/erd/static/js/erd_tool/ERDCore.js
+++ b/web/pgadmin/tools/erd/static/js/erd_tool/ERDCore.js
@@ -305,11 +305,14 @@ export default class ERDCore {
         let fkTableNode = this.getModel().getNodesDict()[linkData.local_table_uid];
 
         let newForeingKeys = [];
+        /* Update the FK table with new references */
         fkTableNode.getData().foreign_key?.forEach((theFkRow)=>{
           for(let fkColumn of theFkRow.columns) {
-            let attnum = _.find(oldTableData.columns, (c)=>c.name==fkColumn.referenced).attnum;
-            fkColumn.referenced = _.find(tableData.columns, (colm)=>colm.attnum==attnum).name;
-            fkColumn.references_table_name = tableData.name;
+            if(fkColumn.references == tableNode.getID()) {
+              let attnum = _.find(oldTableData.columns, (c)=>c.name==fkColumn.referenced).attnum;
+              fkColumn.referenced = _.find(tableData.columns, (colm)=>colm.attnum==attnum).name;
+              fkColumn.references_table_name = tableData.name;
+            }
           }
           newForeingKeys.push(theFkRow);
         });
