MySQL Workbench - Error ERROR 1215 (HY000) with foreign key constraint











up vote
0
down vote

favorite












i have the following two tables:



enter image description here



enter image description here



I need to add UT as foreign key for Id_UT, but the entries in "referenced column" disappear.



enter image description here



It seems to me that all the constraints for the key values are satisfied (datatype, size, uniqueness). What can be wrong here?. Thank you.



Here a minimum working example:






-- MySQL dump 10.13  Distrib 5.7.17, for Win32 (AMD64)
--
-- Host: 127.0.0.1 Database: newschema
-- ------------------------------------------------------
-- Server version 5.7.17

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `catalogo_reperti`
--

DROP TABLE IF EXISTS `catalogo_reperti`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `catalogo_reperti` (
`UT` varchar(45) COLLATE utf16_unicode_ci NOT NULL,
`Id_Reperto` varchar(45) COLLATE utf16_unicode_ci NOT NULL,
`Documentazione` text COLLATE utf16_unicode_ci,
PRIMARY KEY (`Id_Reperto`,`UT`),
UNIQUE KEY `Id_Reperto_UNIQUE` (`Id_Reperto`)
) ENGINE=InnoDB DEFAULT CHARSET=utf16 COLLATE=utf16_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `catalogo_unita_topografiche`
--

DROP TABLE IF EXISTS `catalogo_unita_topografiche`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `catalogo_unita_topografiche` (
`Id_UT` varchar(45) COLLATE utf16_unicode_ci NOT NULL,
PRIMARY KEY (`Id_UT`),
UNIQUE KEY `Id_UT_UNIQUE` (`Id_UT`)
) ENGINE=InnoDB DEFAULT CHARSET=utf16 COLLATE=utf16_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;












share|improve this question




















  • 2




    It's not entirely clear what you are asking. Are you trying to create a foreign key and get an error message, or does the foreign key disappear, or something else?
    – Henning Koehler
    2 days ago










  • The foreign key simply disappears from "referenced column". If I use the alter table command, it returns a generic 1215 error.
    – Discipulos
    2 days ago












  • @Discipulos take a look at the following link. It might helps you MySQL : ERROR 1215 (HY000): Cannot add foreign key constraint
    – Mohammad Mohabbati
    2 days ago










  • I have already checked the question, but all constraints here seem correct and the alter table command returns an error.
    – Discipulos
    2 days ago










  • Could be that Id_UT contains values that don't exist in the other table. The FK constraint would then be violated already when it is created.
    – GolezTrol
    2 days ago















up vote
0
down vote

favorite












i have the following two tables:



enter image description here



enter image description here



I need to add UT as foreign key for Id_UT, but the entries in "referenced column" disappear.



enter image description here



It seems to me that all the constraints for the key values are satisfied (datatype, size, uniqueness). What can be wrong here?. Thank you.



Here a minimum working example:






-- MySQL dump 10.13  Distrib 5.7.17, for Win32 (AMD64)
--
-- Host: 127.0.0.1 Database: newschema
-- ------------------------------------------------------
-- Server version 5.7.17

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `catalogo_reperti`
--

DROP TABLE IF EXISTS `catalogo_reperti`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `catalogo_reperti` (
`UT` varchar(45) COLLATE utf16_unicode_ci NOT NULL,
`Id_Reperto` varchar(45) COLLATE utf16_unicode_ci NOT NULL,
`Documentazione` text COLLATE utf16_unicode_ci,
PRIMARY KEY (`Id_Reperto`,`UT`),
UNIQUE KEY `Id_Reperto_UNIQUE` (`Id_Reperto`)
) ENGINE=InnoDB DEFAULT CHARSET=utf16 COLLATE=utf16_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `catalogo_unita_topografiche`
--

DROP TABLE IF EXISTS `catalogo_unita_topografiche`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `catalogo_unita_topografiche` (
`Id_UT` varchar(45) COLLATE utf16_unicode_ci NOT NULL,
PRIMARY KEY (`Id_UT`),
UNIQUE KEY `Id_UT_UNIQUE` (`Id_UT`)
) ENGINE=InnoDB DEFAULT CHARSET=utf16 COLLATE=utf16_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;












share|improve this question




















  • 2




    It's not entirely clear what you are asking. Are you trying to create a foreign key and get an error message, or does the foreign key disappear, or something else?
    – Henning Koehler
    2 days ago










  • The foreign key simply disappears from "referenced column". If I use the alter table command, it returns a generic 1215 error.
    – Discipulos
    2 days ago












  • @Discipulos take a look at the following link. It might helps you MySQL : ERROR 1215 (HY000): Cannot add foreign key constraint
    – Mohammad Mohabbati
    2 days ago










  • I have already checked the question, but all constraints here seem correct and the alter table command returns an error.
    – Discipulos
    2 days ago










  • Could be that Id_UT contains values that don't exist in the other table. The FK constraint would then be violated already when it is created.
    – GolezTrol
    2 days ago













up vote
0
down vote

favorite









up vote
0
down vote

favorite











i have the following two tables:



enter image description here



enter image description here



I need to add UT as foreign key for Id_UT, but the entries in "referenced column" disappear.



enter image description here



It seems to me that all the constraints for the key values are satisfied (datatype, size, uniqueness). What can be wrong here?. Thank you.



Here a minimum working example:






-- MySQL dump 10.13  Distrib 5.7.17, for Win32 (AMD64)
--
-- Host: 127.0.0.1 Database: newschema
-- ------------------------------------------------------
-- Server version 5.7.17

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `catalogo_reperti`
--

DROP TABLE IF EXISTS `catalogo_reperti`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `catalogo_reperti` (
`UT` varchar(45) COLLATE utf16_unicode_ci NOT NULL,
`Id_Reperto` varchar(45) COLLATE utf16_unicode_ci NOT NULL,
`Documentazione` text COLLATE utf16_unicode_ci,
PRIMARY KEY (`Id_Reperto`,`UT`),
UNIQUE KEY `Id_Reperto_UNIQUE` (`Id_Reperto`)
) ENGINE=InnoDB DEFAULT CHARSET=utf16 COLLATE=utf16_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `catalogo_unita_topografiche`
--

DROP TABLE IF EXISTS `catalogo_unita_topografiche`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `catalogo_unita_topografiche` (
`Id_UT` varchar(45) COLLATE utf16_unicode_ci NOT NULL,
PRIMARY KEY (`Id_UT`),
UNIQUE KEY `Id_UT_UNIQUE` (`Id_UT`)
) ENGINE=InnoDB DEFAULT CHARSET=utf16 COLLATE=utf16_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;












share|improve this question















i have the following two tables:



enter image description here



enter image description here



I need to add UT as foreign key for Id_UT, but the entries in "referenced column" disappear.



enter image description here



It seems to me that all the constraints for the key values are satisfied (datatype, size, uniqueness). What can be wrong here?. Thank you.



Here a minimum working example:






-- MySQL dump 10.13  Distrib 5.7.17, for Win32 (AMD64)
--
-- Host: 127.0.0.1 Database: newschema
-- ------------------------------------------------------
-- Server version 5.7.17

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `catalogo_reperti`
--

DROP TABLE IF EXISTS `catalogo_reperti`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `catalogo_reperti` (
`UT` varchar(45) COLLATE utf16_unicode_ci NOT NULL,
`Id_Reperto` varchar(45) COLLATE utf16_unicode_ci NOT NULL,
`Documentazione` text COLLATE utf16_unicode_ci,
PRIMARY KEY (`Id_Reperto`,`UT`),
UNIQUE KEY `Id_Reperto_UNIQUE` (`Id_Reperto`)
) ENGINE=InnoDB DEFAULT CHARSET=utf16 COLLATE=utf16_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `catalogo_unita_topografiche`
--

DROP TABLE IF EXISTS `catalogo_unita_topografiche`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `catalogo_unita_topografiche` (
`Id_UT` varchar(45) COLLATE utf16_unicode_ci NOT NULL,
PRIMARY KEY (`Id_UT`),
UNIQUE KEY `Id_UT_UNIQUE` (`Id_UT`)
) ENGINE=InnoDB DEFAULT CHARSET=utf16 COLLATE=utf16_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;








-- MySQL dump 10.13  Distrib 5.7.17, for Win32 (AMD64)
--
-- Host: 127.0.0.1 Database: newschema
-- ------------------------------------------------------
-- Server version 5.7.17

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `catalogo_reperti`
--

DROP TABLE IF EXISTS `catalogo_reperti`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `catalogo_reperti` (
`UT` varchar(45) COLLATE utf16_unicode_ci NOT NULL,
`Id_Reperto` varchar(45) COLLATE utf16_unicode_ci NOT NULL,
`Documentazione` text COLLATE utf16_unicode_ci,
PRIMARY KEY (`Id_Reperto`,`UT`),
UNIQUE KEY `Id_Reperto_UNIQUE` (`Id_Reperto`)
) ENGINE=InnoDB DEFAULT CHARSET=utf16 COLLATE=utf16_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `catalogo_unita_topografiche`
--

DROP TABLE IF EXISTS `catalogo_unita_topografiche`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `catalogo_unita_topografiche` (
`Id_UT` varchar(45) COLLATE utf16_unicode_ci NOT NULL,
PRIMARY KEY (`Id_UT`),
UNIQUE KEY `Id_UT_UNIQUE` (`Id_UT`)
) ENGINE=InnoDB DEFAULT CHARSET=utf16 COLLATE=utf16_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;





-- MySQL dump 10.13  Distrib 5.7.17, for Win32 (AMD64)
--
-- Host: 127.0.0.1 Database: newschema
-- ------------------------------------------------------
-- Server version 5.7.17

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `catalogo_reperti`
--

DROP TABLE IF EXISTS `catalogo_reperti`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `catalogo_reperti` (
`UT` varchar(45) COLLATE utf16_unicode_ci NOT NULL,
`Id_Reperto` varchar(45) COLLATE utf16_unicode_ci NOT NULL,
`Documentazione` text COLLATE utf16_unicode_ci,
PRIMARY KEY (`Id_Reperto`,`UT`),
UNIQUE KEY `Id_Reperto_UNIQUE` (`Id_Reperto`)
) ENGINE=InnoDB DEFAULT CHARSET=utf16 COLLATE=utf16_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `catalogo_unita_topografiche`
--

DROP TABLE IF EXISTS `catalogo_unita_topografiche`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `catalogo_unita_topografiche` (
`Id_UT` varchar(45) COLLATE utf16_unicode_ci NOT NULL,
PRIMARY KEY (`Id_UT`),
UNIQUE KEY `Id_UT_UNIQUE` (`Id_UT`)
) ENGINE=InnoDB DEFAULT CHARSET=utf16 COLLATE=utf16_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;






mysql sql mysql-workbench






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago

























asked 2 days ago









Discipulos

155113




155113








  • 2




    It's not entirely clear what you are asking. Are you trying to create a foreign key and get an error message, or does the foreign key disappear, or something else?
    – Henning Koehler
    2 days ago










  • The foreign key simply disappears from "referenced column". If I use the alter table command, it returns a generic 1215 error.
    – Discipulos
    2 days ago












  • @Discipulos take a look at the following link. It might helps you MySQL : ERROR 1215 (HY000): Cannot add foreign key constraint
    – Mohammad Mohabbati
    2 days ago










  • I have already checked the question, but all constraints here seem correct and the alter table command returns an error.
    – Discipulos
    2 days ago










  • Could be that Id_UT contains values that don't exist in the other table. The FK constraint would then be violated already when it is created.
    – GolezTrol
    2 days ago














  • 2




    It's not entirely clear what you are asking. Are you trying to create a foreign key and get an error message, or does the foreign key disappear, or something else?
    – Henning Koehler
    2 days ago










  • The foreign key simply disappears from "referenced column". If I use the alter table command, it returns a generic 1215 error.
    – Discipulos
    2 days ago












  • @Discipulos take a look at the following link. It might helps you MySQL : ERROR 1215 (HY000): Cannot add foreign key constraint
    – Mohammad Mohabbati
    2 days ago










  • I have already checked the question, but all constraints here seem correct and the alter table command returns an error.
    – Discipulos
    2 days ago










  • Could be that Id_UT contains values that don't exist in the other table. The FK constraint would then be violated already when it is created.
    – GolezTrol
    2 days ago








2




2




It's not entirely clear what you are asking. Are you trying to create a foreign key and get an error message, or does the foreign key disappear, or something else?
– Henning Koehler
2 days ago




It's not entirely clear what you are asking. Are you trying to create a foreign key and get an error message, or does the foreign key disappear, or something else?
– Henning Koehler
2 days ago












The foreign key simply disappears from "referenced column". If I use the alter table command, it returns a generic 1215 error.
– Discipulos
2 days ago






The foreign key simply disappears from "referenced column". If I use the alter table command, it returns a generic 1215 error.
– Discipulos
2 days ago














@Discipulos take a look at the following link. It might helps you MySQL : ERROR 1215 (HY000): Cannot add foreign key constraint
– Mohammad Mohabbati
2 days ago




@Discipulos take a look at the following link. It might helps you MySQL : ERROR 1215 (HY000): Cannot add foreign key constraint
– Mohammad Mohabbati
2 days ago












I have already checked the question, but all constraints here seem correct and the alter table command returns an error.
– Discipulos
2 days ago




I have already checked the question, but all constraints here seem correct and the alter table command returns an error.
– Discipulos
2 days ago












Could be that Id_UT contains values that don't exist in the other table. The FK constraint would then be violated already when it is created.
– GolezTrol
2 days ago




Could be that Id_UT contains values that don't exist in the other table. The FK constraint would then be violated already when it is created.
– GolezTrol
2 days ago












1 Answer
1






active

oldest

votes

















up vote
0
down vote













Forcing the declaration of Charset/collation (instead of leaving the default ones, which anyway are set to be the same) allows the program to declare the foreign key.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238316%2fmysql-workbench-error-error-1215-hy000-with-foreign-key-constraint%23new-answer', 'question_page');
    }
    );

    Post as a guest
































    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    Forcing the declaration of Charset/collation (instead of leaving the default ones, which anyway are set to be the same) allows the program to declare the foreign key.






    share|improve this answer

























      up vote
      0
      down vote













      Forcing the declaration of Charset/collation (instead of leaving the default ones, which anyway are set to be the same) allows the program to declare the foreign key.






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        Forcing the declaration of Charset/collation (instead of leaving the default ones, which anyway are set to be the same) allows the program to declare the foreign key.






        share|improve this answer












        Forcing the declaration of Charset/collation (instead of leaving the default ones, which anyway are set to be the same) allows the program to declare the foreign key.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 days ago









        Discipulos

        155113




        155113






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238316%2fmysql-workbench-error-error-1215-hy000-with-foreign-key-constraint%23new-answer', 'question_page');
            }
            );

            Post as a guest




















































































            Popular posts from this blog

            Full-time equivalent

            さくらももこ

            13 indicted, 8 arrested in Calif. drug cartel investigation