Fix Bug #16290 Unclear error message when adding foreign key constraint
rb://502 approved by Sunny Bains
This commit is contained in:
parent
a8266151de
commit
f64026427e
@ -3483,7 +3483,7 @@ col_loop1:
|
||||
start_of_latest_foreign);
|
||||
mutex_exit(&dict_foreign_err_mutex);
|
||||
|
||||
return(DB_CANNOT_ADD_CONSTRAINT);
|
||||
return(DB_CHILD_NO_INDEX);
|
||||
}
|
||||
ptr = dict_accept(cs, ptr, "REFERENCES", &success);
|
||||
|
||||
@ -3764,7 +3764,7 @@ try_find_index:
|
||||
start_of_latest_foreign);
|
||||
mutex_exit(&dict_foreign_err_mutex);
|
||||
|
||||
return(DB_CANNOT_ADD_CONSTRAINT);
|
||||
return(DB_PARENT_NO_INDEX);
|
||||
}
|
||||
} else {
|
||||
ut_a(trx->check_foreigns == FALSE);
|
||||
|
@ -960,6 +960,8 @@ convert_error_code_to_mysql(
|
||||
return(HA_ERR_ROW_IS_REFERENCED);
|
||||
|
||||
case DB_CANNOT_ADD_CONSTRAINT:
|
||||
case DB_CHILD_NO_INDEX:
|
||||
case DB_PARENT_NO_INDEX:
|
||||
return(HA_ERR_CANNOT_ADD_FOREIGN);
|
||||
|
||||
case DB_CANNOT_DROP_CONSTRAINT:
|
||||
@ -6977,6 +6979,29 @@ ha_innobase::create(
|
||||
trx, stmt, stmt_len, norm_name,
|
||||
create_info->options & HA_LEX_CREATE_TMP_TABLE);
|
||||
|
||||
switch (error) {
|
||||
|
||||
case DB_PARENT_NO_INDEX:
|
||||
push_warning_printf(
|
||||
thd, MYSQL_ERROR::WARN_LEVEL_WARN,
|
||||
HA_ERR_CANNOT_ADD_FOREIGN,
|
||||
"Create table '%s' with foreign key constraint"
|
||||
" failed. There is no index in the referenced"
|
||||
" table where the referenced columns appear"
|
||||
" as the first columns.\n", norm_name);
|
||||
break;
|
||||
|
||||
case DB_CHILD_NO_INDEX:
|
||||
push_warning_printf(
|
||||
thd, MYSQL_ERROR::WARN_LEVEL_WARN,
|
||||
HA_ERR_CANNOT_ADD_FOREIGN,
|
||||
"Create table '%s' with foreign key constraint"
|
||||
" failed. There is no index in the referencing"
|
||||
" table where referencing columns appear"
|
||||
" as the first columns.\n", norm_name);
|
||||
break;
|
||||
}
|
||||
|
||||
error = convert_error_code_to_mysql(error, flags, NULL);
|
||||
|
||||
if (error) {
|
||||
|
@ -104,6 +104,12 @@ enum db_err {
|
||||
DB_FOREIGN_EXCEED_MAX_CASCADE, /* Foreign key constraint related
|
||||
cascading delete/update exceeds
|
||||
maximum allowed depth */
|
||||
DB_CHILD_NO_INDEX, /* the child (foreign) table does not
|
||||
have an index that contains the
|
||||
foreign keys as its prefix columns */
|
||||
DB_PARENT_NO_INDEX, /* the parent table does not
|
||||
have an index that contains the
|
||||
foreign keys as its prefix columns */
|
||||
|
||||
/* The following are partial failure codes */
|
||||
DB_FAIL = 1000,
|
||||
|
@ -715,6 +715,10 @@ ut_strerr(
|
||||
return("Zip overflow");
|
||||
case DB_RECORD_NOT_FOUND:
|
||||
return("Record not found");
|
||||
case DB_CHILD_NO_INDEX:
|
||||
return("No index on referencing keys in referencing table");
|
||||
case DB_PARENT_NO_INDEX:
|
||||
return("No index on referenced keys in referenced table");
|
||||
case DB_END_OF_INDEX:
|
||||
return("End of index");
|
||||
/* do not add default: in order to produce a warning if new code
|
||||
|
Loading…
x
Reference in New Issue
Block a user