Jump to content

Columns and foreign keys


random1

Recommended Posts

I have two columns on two seperate tables that are IDs, one is primary and the other is not primary.

 

`version_id` BIGINT(50) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'The ID of the Version'

 

`versionchange_version_id` BIGINT(50) UNSIGNED NOT NULL COMMENT 'The Name of the Version ID'

 

When I try to create a FK relationship I get the error:

 

/* SQL Error (1452): Cannot add or update a child row: a foreign key constraint fails (`webman`.<result 2 when explaining filename '#sql-704_8'>, CONSTRAINT `FK_version_change_version` FOREIGN KEY (`versionchange_version_id`) REFERENCES `version` (`version_id`)) */

 

To set up a foreign key relationship do both fields need to be AUTO_INCREMENT?

 

I am using InnoDB with the latest version of MySQL if that makes any difference.

Link to comment
https://forums.phpfreaks.com/topic/204162-columns-and-foreign-keys/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.