I have two tables which are customer and transaction tables. Transaction table have two foreign keys which refers two fields in the customer table.
I added the customer table but when I try to add the transaction table, it gives me:
SQL Error[1215][HY000] Cannot add foreign key constraints
Following are my tables.
CREATE TABLE customerDetails(
CustomerID varchar(10)NOT NULL,
AccountNumber varchar(15) NOT NULL,
CustomerName varchar(60)NOT NULL,
Address varchar(60),
phone varchar(15),
email varchar(50),
joinedDate date,
primary key(CustomerID)
)
CREATE TABLE transactions(
TraceNumber varchar(30) NOT NULL,
AccountNumber varchar(15)NOT NULL,
CustomerName varchar(60)NOT NULL,
TransactionType varchar(15) NOT NULL,
TransactionDateTime datetime NOT NULL,
TransactionAmount double DEFAULT NULL,
PRIMARY KEY (TraceNumber),
FOREIGN KEY(CustomerName) REFERENCES customerDetails(CustomerName),
FOREIGN KEY(AccountNumber) REFERENCES customerDetails(AccountNumber)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;