V
V
Vladimir Golub2015-05-01 10:21:35
MySQL
Vladimir Golub, 2015-05-01 10:21:35

Why can't foreign key be VARCHAR?

0326bba208744bf6944c48dd6ffbda5b.png
There are two key fields in the "Customers" table - client code (a set of numbers and letters) and client id.
I link it to the "Orders 1C" table, these two key fields are transferred there. I don’t really need the client’s id there, I identify the ownership of orders by the client code in 1C.
Why doesn't MySQL allow deleting the client id and writes an error ?
#1025 - Error on rename of './odeon/#sql-ec9_68c' to './odeon/orders_1c' (errno: 150)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Melkij, 2015-05-01
@RazerVG

Since there are no foreign keys in mysql architecturally, and in innodb they are screwed somehow on the side, the error messages are striking in their uselessness. How to get normal messages is indicated in the manual:
https://dev.mysql.com/doc/refman/5.6/en/innodb-for...

Foreign Key Usage and Error Information
You can obtain general information about foreign keys and their usage from querying the INFORMATION_SCHEMA.KEY_COLUMN_USAGE table, and more information more specific to InnoDB tables can be found in the INNODB_SYS_FOREIGN and INNODB_SYS_FOREIGN_COLS tables, also in the INFORMATION_SCHEMA database. See also Section 13.1.17.3, “Using FOREIGN KEY Constraints”.
In addition to SHOW ERRORS, in the event of a foreign key error involving InnoDB tables (usually Error 150 in the MySQL Server), you can obtain a detailed explanation of the most recent InnoDB foreign key error by checking the output of SHOW ENGINE INNODB STATUS .

A
AVKor, 2015-05-01
@AVKor

The FK of the child must match the CK of the parent.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question