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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.