I am trying to make a one-to-one relationship in a MySQL database. I am using the InnoDB engine, and the main table looks like this:
CREATE TABLE `foo` (
`fooID` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`name` TEXT NOT NULL
)
CREATE TABLE `bar` (
`barName` VARCHAR(100) NOT NULL,
`fooID` INT(11) NOT NULL PRIMARY KEY,
CONSTRAINT `contact` FOREIGN KEY (`fooID`) REFERENCES `foo`(`fooID`)
)
Now, as soon as I set them up, I modify the table foo so that fooID also becomes the foreign key in fooID in the row. The only problem I encountered is that when trying to insert into it there will be a problem with integrity. I need help, thanks.
Botto source
share