MySQL Error Code: 1005

I am trying to add foreign keys to my table but getting this error. Error code: 1005 Unable to create table 'william. # Sql-88c_3 '(errno: 150) I have 3 tables. employee, client and contract.

use [employee_no PK], client [customer_no PK] contract [contract_no PK] I want to have foreign keys for the contract as a contract [contract_no PK, employee_no FK], customer_no FK]

I tried to do this directly, but now I'm trying to change the expression. Is there something wrong with the Alter script?

    ALTER TABLE contract
    ADD CONSTRAINT `employee_no_fk2` FOREIGN KEY (`employee_no`) REFERENCES `employee` 
    (`employee_no`);


   ALTER TABLE contract
    ADD CONSTRAINT `Customer_no_fk2` FOREIGN KEY (`Customer_no`) REFERENCES `client` 
    (`Customer_no`);
+3
source share
4 answers

.. .. . ... Check-this

:

, : .

mysql> SHOW engine innodb STATUS;

------------------------
LATEST FOREIGN KEY ERROR
------------------------
100130 17:16:57 Error IN FOREIGN KEY CONSTRAINT OF TABLE sampledb/#sql-4a0_2:
FOREIGN KEY(member_type)
REFERENCES common_lookup(common_lookup_id):
Cannot find an INDEX IN the referenced TABLE WHERE the
referenced COLUMNS appear AS the FIRST COLUMNS, OR COLUMN types
IN the TABLE AND the referenced TABLE do NOT MATCH FOR CONSTRAINT.
+10

, , , / . / , , InnoDB.

+2

The last time I came across this, these were limitations: the table table reference type was "int", and the referring table had the "unsigned int" field, by mistake, instead of int.

0
source

Source: https://habr.com/ru/post/1765202/


All Articles