Note that there are some explanatory texts on larger screens.

plurals
  1. POmysql foreign keys
    text
    copied!<p>Hello I have two mysql tables one that holds username and password second that holds user information. Here are the tables:</p> <pre><code>CREATE TABLE IF NOT EXISTS `test`.`dbo.users` ( `userId` INT(11) NOT NULL AUTO_INCREMENT , `userUsername` VARCHAR(45) NULL , `userPassword` VARCHAR(45) NULL , `dbo.userProfiles_userProfileId` INT(11) NOT NULL , PRIMARY KEY (`userId`, `dbo.userProfiles_userProfileId`) , INDEX `fk_dbo.users_dbo.userProfiles` (`dbo.userProfiles_userProfileId` ASC) , CONSTRAINT `fk_dbo.users_dbo.userProfiles` FOREIGN KEY (`dbo.userProfiles_userProfileId` ) REFERENCES `test`.`dbo.userProfiles` (`userId` ) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE = InnoDB; CREATE TABLE IF NOT EXISTS `test`.`dbo.userProfiles` ( `userProfileId` INT(11) NOT NULL AUTO_INCREMENT , `userId` INT(11) NOT NULL , `userFirstName` VARCHAR(45) NULL , `userMidleName` VARCHAR(45) NULL , `userLastName` VARCHAR(45) NULL , `userBirthDate` VARCHAR(45) NULL , `userCountry` VARCHAR(45) NULL , `userState` VARCHAR(45) NULL , `userCity` VARCHAR(45) NULL , `userZipCode` VARCHAR(45) NULL , `userPrimaryAddress` VARCHAR(45) NULL , `userSecondaryAddress` VARCHAR(45) NULL , `userThirdAddress` VARCHAR(45) NULL , `userFirstPhone` VARCHAR(45) NULL , `userSecondaryPhone` VARCHAR(45) NULL , `userThirdPhone` VARCHAR(45) NULL , `userFirstEmail` VARCHAR(45) NULL , `userSecondaryEmail` VARCHAR(45) NULL , `userThirdEmail` VARCHAR(45) NULL , `userDescription` VARCHAR(45) NULL , PRIMARY KEY (`userProfileId`, `userId`) ) ENGINE = InnoDB; </code></pre> <p>My problem with this tables is that the fk key doesn't work and I'm not sure why I'm missing something here.. ( I haven't used foreign keys much).</p> <p>Error: </p> <blockquote> <p>Executing SQL script in server</p> <p>ERROR: Error 1005: Can't create table 'test.dbo.users' (errno: 150)</p> </blockquote> <p>Can you please help fixing this so I can use fk on this tables and others? and if you got some time to spare to explain me how fk keys work exactly (using mysql workbench to create them on a diagram then forward engineer). thank you for your help</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload