random1 Posted June 8, 2010 Share Posted June 8, 2010 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 More sharing options...
ignace Posted June 8, 2010 Share Posted June 8, 2010 No, a FK does not need the AUTO_INCREMENT attribute. And why do you use BIGINT?? Did you create the PK first before creating the FK? Link to comment https://forums.phpfreaks.com/topic/204162-columns-and-foreign-keys/#findComment-1069303 Share on other sites More sharing options...
random1 Posted June 8, 2010 Author Share Posted June 8, 2010 Yes I created the PK first. The BIGINT supports my efforts for 32-bit and 64-bit compatability. Link to comment https://forums.phpfreaks.com/topic/204162-columns-and-foreign-keys/#findComment-1069311 Share on other sites More sharing options...
Mchl Posted June 8, 2010 Share Posted June 8, 2010 The BIGINT supports my efforts for 32-bit and 64-bit compatability. How exactly? Link to comment https://forums.phpfreaks.com/topic/204162-columns-and-foreign-keys/#findComment-1069317 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.