I have seen a lot of questions in Stackoerflow before asking this question
When I execute the below mlm_commission create table query,
I am getting the following error.
1005 - Can't create table 'mlm_new.mlm_commission' (errno: 150) (Details…)
Also When I click Details, I got the following text
Supports transactions, row-level locking, and foreign keys
Create Commission Table
CREATE TABLE IF NOT EXISTS mlm_commission
(`weekno` int(11) NOT NULL,
`level` int(11) NOT NULL,
`username` varchar(500) NOT NULL,
`PositionA` int(11) NOT NULL,
`CFPositionA` int(11) NOT NULL,
`PositionB` int(11) NOT NULL,
`CFPositionB` int(11) NOT NULL,
`PositionC` int(11) NOT NULL,
`CFPositionC` int(11) NOT NULL,
`ABLeft` int(11) NOT NULL,
`CFABLeft` int(11) NOT NULL,
`ABRight` int(11) NOT NULL,
`CFABRight` int(11) NOT NULL,
`CLeft` int(11) NOT NULL,
`CFCLeft` int(11) NOT NULL,
`CRight` int(11) NOT NULL,
`CFCRight` int(11) NOT NULL,
`ABMatchingPair` int(11) NOT NULL,
`CMatchingPair` int(11) NOT NULL,
`IsIncludedToParent` enum('Y','N'),
`side` enum('L','R') NOT NULL,
`leg` enum('0','1','2') NOT NULL,
`parent_key` varchar(15) NOT NULL,
`commission` int(11) NOT NULL,
FOREIGN KEY(`username`) REFERENCES mlm_rtmfx_users(`username`),
FOREIGN KEY(`side`) REFERENCES mlm_rtmfx_users(`side`),
FOREIGN KEY(`leg`) REFERENCES mlm_rtmfx_users(`leg`),
FOREIGN KEY(`parent_key`) REFERENCES mlm_rtmfx_users(`parent_key`),
PRIMARY KEY(`username`,`weekno`,`level`));
I am referencing 4 foreign key values in mlm_rtmfx_commission table from the below table.
CREATE TABLE `mlm_rtmfx_users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` varchar(1023) NOT NULL,
`username` varchar(500) NOT NULL,
`user_key` varchar(15) NOT NULL,
`parent_key` varchar(15) NOT NULL,
`sponsor_key` varchar(15) NOT NULL,
`leg` enum('0','1','2') NOT NULL,
`payment_status` enum('0','1') NOT NULL,
`pinno` int(11) NOT NULL,
`user_password` varchar(8) NOT NULL,
`side` enum('L','R') NOT NULL,
`iseligible` enum('Y','N') NOT NULL,
`created_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
)
You can check that each foreign key references are having same name and type.
I have seen this Error No:150 and I am confusing about indexes.
I also having the list of indexes in mlm_rtmfx_users table. Please check below.
I got the index table from the following query.
SHOW INDEX FROM mlm_rtmfx_users
Please clarify me where do I go wrong? If my question is not clear, Please let me know.