IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

MySQL Discussion :

Cannot add foreign key constraint


Sujet :

MySQL

  1. #1
    Membre du Club
    Homme Profil pro
    Auditeur informatique
    Inscrit en
    Septembre 2015
    Messages
    35
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Auditeur informatique

    Informations forums :
    Inscription : Septembre 2015
    Messages : 35
    Points : 42
    Points
    42
    Par défaut Cannot add foreign key constraint
    Bonjour à tous,

    je souhaite faire une mise à jour d'un site wp et pour cela je veux tranférer le site en local pour voir s'il y a des bugs.

    Lorsque j'importe ma bdd j'ai cette erreur qui s'affiche:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    Error
    SQL query:
     
     
    ALTER TABLE `wp_hmenu_main_styles`
      ADD CONSTRAINT `hmenu_main_styles_menuId_1821200116_FK` FOREIGN KEY (`menuId`) REFERENCES `wp_hmenu_menu` (`menuId`) ON DELETE NO ACTION ON UPDATE NO ACTION
    MySQL said: Documentation
     
    #1215 - Cannot add foreign key constraint
    Voici la table que je souhaite importer:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
     
    -- phpMyAdmin SQL Dump
    -- version 4.4.15.7
    -- http://www.phpmyadmin.net
    --
    -- Client :  adeisowp.mysql.db
    -- Généré le :  Mar 04 Avril 2017 à 13:39
    -- Version du serveur :  5.5.54-0+deb7u1-log
    -- Version de PHP :  5.4.45-0+deb7u6
     
    SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
    SET time_zone = "+00:00";
     
     
    /*!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 utf8mb4 */;
     
    --
    -- Base de données :  `adeisowp`
    --
     
    -- --------------------------------------------------------
     
    --
    -- Structure de la table `wp_hmenu_main_styles`
    --
     
    CREATE TABLE IF NOT EXISTS `wp_hmenu_main_styles` (
      `mainStyleId` int(11) NOT NULL,
      `menuId` int(11) NOT NULL,
      `logo` tinyint(1) DEFAULT NULL,
      `logoUrl` varchar(255) DEFAULT NULL,
      `logoLink` varchar(255) DEFAULT NULL,
      `logoAlt` varchar(255) DEFAULT NULL,
      `logoLinkTarget` varchar(20) NOT NULL DEFAULT '_self',
      `logoHeight` varchar(10) DEFAULT NULL,
      `mobileLogo` tinyint(1) DEFAULT NULL,
      `mobileLogoUrl` varchar(255) DEFAULT NULL,
      `mobileLogoHeight` varchar(10) DEFAULT NULL,
      `search` tinyint(1) DEFAULT NULL,
      `menu` tinyint(1) DEFAULT NULL,
      `social` tinyint(1) DEFAULT NULL,
      `cart` tinyint(1) DEFAULT NULL,
      `menuBarDimentions` varchar(11) DEFAULT NULL,
      `menuBarWidth` varchar(11) DEFAULT NULL,
      `menuBarHeight` varchar(11) DEFAULT NULL,
      `navBarDimentions` varchar(11) DEFAULT NULL,
      `navBarWidth` varchar(11) DEFAULT NULL,
      `border` tinyint(1) DEFAULT NULL,
      `borderColor` varchar(11) DEFAULT NULL,
      `borderTransparency` decimal(2,1) DEFAULT NULL,
      `borderType` varchar(40) DEFAULT NULL,
      `borderRadius` varchar(100) DEFAULT NULL,
      `shadow` tinyint(1) DEFAULT NULL,
      `shadowRadius` varchar(20) DEFAULT NULL,
      `shadowColor` varchar(11) DEFAULT NULL,
      `shadowTransparency` decimal(2,1) DEFAULT NULL,
      `bgMenuStartColor` varchar(11) DEFAULT NULL,
      `bgMenuGradient` tinyint(1) DEFAULT NULL,
      `bgMenuEndColor` varchar(11) DEFAULT NULL,
      `bgMenuGradientPath` varchar(11) DEFAULT NULL,
      `bgMenuTransparency` decimal(2,1) DEFAULT NULL,
      `bgHoverStartColor` varchar(11) DEFAULT NULL,
      `bgHoverType` varchar(11) DEFAULT NULL,
      `bgHoverGradient` tinyint(1) DEFAULT NULL,
      `bgHoverEndColor` varchar(11) DEFAULT NULL,
      `bgHoverGradientPath` varchar(11) DEFAULT NULL,
      `bgHoverTransparency` decimal(2,1) DEFAULT NULL,
      `paddingLeft` varchar(11) DEFAULT NULL,
      `paddingRight` varchar(11) DEFAULT NULL,
      `orientation` varchar(11) DEFAULT NULL,
      `verticalWidth` varchar(11) DEFAULT NULL,
      `animation` varchar(45) DEFAULT NULL,
      `animationDuration` int(11) DEFAULT NULL,
      `animationTrigger` varchar(11) DEFAULT NULL,
      `animationTimeout` varchar(11) DEFAULT NULL,
      `sticky` tinyint(1) DEFAULT NULL,
      `stickyLogoActive` tinyint(1) DEFAULT NULL,
      `stickyUrl` varchar(150) DEFAULT NULL,
      `stickyActivate` varchar(11) DEFAULT NULL,
      `stickyHeight` varchar(11) DEFAULT NULL,
      `stickyFontColor` varchar(11) DEFAULT NULL,
      `stickyFontHoverColor` varchar(45) DEFAULT NULL,
      `stickyFontSize` varchar(11) DEFAULT NULL,
      `stickyFontSizing` varchar(11) DEFAULT NULL,
      `stickyFontWeight` varchar(11) DEFAULT NULL,
      `stickyFontHoverDecoration` varchar(25) DEFAULT NULL,
      `bgStickyStart` varchar(11) DEFAULT NULL,
      `bgStickyEnd` varchar(11) DEFAULT NULL,
      `stickyTransparency` decimal(2,1) DEFAULT NULL,
      `devider` tinyint(1) DEFAULT NULL,
      `deviderTransparency` decimal(2,1) DEFAULT NULL,
      `deviderColor` varchar(11) DEFAULT NULL,
      `deviderSizing` varchar(11) DEFAULT NULL,
      `groupDevider` tinyint(1) DEFAULT NULL,
      `groupTransparency` decimal(2,1) DEFAULT NULL,
      `groupColor` varchar(11) DEFAULT NULL,
      `groupSizing` varchar(11) DEFAULT NULL,
      `responsiveLabel` varchar(100) DEFAULT NULL,
      `icons` tinyint(1) DEFAULT NULL,
      `iconsColor` varchar(11) DEFAULT NULL,
      `arrows` tinyint(1) DEFAULT NULL,
      `arrowTransparency` decimal(2,1) DEFAULT NULL,
      `arrowColor` varchar(11) DEFAULT NULL,
      `fontFamily` varchar(45) DEFAULT NULL,
      `fontColor` varchar(11) DEFAULT NULL,
      `fontHoverColor` varchar(45) DEFAULT NULL,
      `fontSize` varchar(11) DEFAULT NULL,
      `fontSizing` varchar(11) DEFAULT NULL,
      `fontWeight` varchar(11) DEFAULT NULL,
      `fontDecoration` varchar(25) DEFAULT NULL,
      `fontHoverDecoration` varchar(25) DEFAULT NULL,
      `zindex` varchar(25) DEFAULT NULL,
      `preset` tinyint(1) DEFAULT NULL,
      `presetSlug` varchar(50) DEFAULT NULL,
      `iconProductSize` varchar(11) DEFAULT NULL,
      `iconProductColor` varchar(20) DEFAULT NULL,
      `iconProductHoverColor` varchar(45) DEFAULT NULL,
      `siteResponsive` tinyint(1) DEFAULT NULL,
      `siteResponsiveOne` varchar(11) DEFAULT NULL,
      `siteResponsiveTwo` varchar(11) DEFAULT NULL,
      `siteResponsiveThree` varchar(11) DEFAULT NULL,
      `logoPaddingLeft` varchar(11) NOT NULL DEFAULT '0',
      `mobileLogoPaddingLeft` varchar(11) NOT NULL DEFAULT '10',
      `stickyLogoPaddingLeft` varchar(11) NOT NULL DEFAULT '10',
      `bgMainImage` tinyint(1) DEFAULT NULL,
      `bgMainImageUrl` varchar(255) DEFAULT NULL,
      `bgMainImagePosition` varchar(50) DEFAULT NULL,
      `bgMainImageRepeat` varchar(50) DEFAULT NULL,
      `customCss` blob,
      `logoPaddingRight` varchar(11) NOT NULL DEFAULT '0',
      `bgStickyHoverColor` varchar(11) DEFAULT NULL,
      `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
      `lastModified` datetime DEFAULT NULL,
      `deleted` tinyint(1) NOT NULL DEFAULT '0'
    ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
     
    --
    -- Contenu de la table `wp_hmenu_main_styles`
    --
     
    INSERT INTO `wp_hmenu_main_styles` (`mainStyleId`, `menuId`, `logo`, `logoUrl`, `logoLink`, `logoAlt`, `logoLinkTarget`, `logoHeight`, `mobileLogo`, `mobileLogoUrl`, `mobileLogoHeight`, `search`, `menu`, `social`, `cart`, `menuBarDimentions`, `menuBarWidth`, `menuBarHeight`, `navBarDimentions`, `navBarWidth`, `border`, `borderColor`, `borderTransparency`, `borderType`, `borderRadius`, `shadow`, `shadowRadius`, `shadowColor`, `shadowTransparency`, `bgMenuStartColor`, `bgMenuGradient`, `bgMenuEndColor`, `bgMenuGradientPath`, `bgMenuTransparency`, `bgHoverStartColor`, `bgHoverType`, `bgHoverGradient`, `bgHoverEndColor`, `bgHoverGradientPath`, `bgHoverTransparency`, `paddingLeft`, `paddingRight`, `orientation`, `verticalWidth`, `animation`, `animationDuration`, `animationTrigger`, `animationTimeout`, `sticky`, `stickyLogoActive`, `stickyUrl`, `stickyActivate`, `stickyHeight`, `stickyFontColor`, `stickyFontHoverColor`, `stickyFontSize`, `stickyFontSizing`, `stickyFontWeight`, `stickyFontHoverDecoration`, `bgStickyStart`, `bgStickyEnd`, `stickyTransparency`, `devider`, `deviderTransparency`, `deviderColor`, `deviderSizing`, `groupDevider`, `groupTransparency`, `groupColor`, `groupSizing`, `responsiveLabel`, `icons`, `iconsColor`, `arrows`, `arrowTransparency`, `arrowColor`, `fontFamily`, `fontColor`, `fontHoverColor`, `fontSize`, `fontSizing`, `fontWeight`, `fontDecoration`, `fontHoverDecoration`, `zindex`, `preset`, `presetSlug`, `iconProductSize`, `iconProductColor`, `iconProductHoverColor`, `siteResponsive`, `siteResponsiveOne`, `siteResponsiveTwo`, `siteResponsiveThree`, `logoPaddingLeft`, `mobileLogoPaddingLeft`, `stickyLogoPaddingLeft`, `bgMainImage`, `bgMainImageUrl`, `bgMainImagePosition`, `bgMainImageRepeat`, `customCss`, `logoPaddingRight`, `bgStickyHoverColor`, `created`, `lastModified`, `deleted`) VALUES
    (1, 1, 0, '', '', '', '_self', '80', 0, '', '80', 0, 1, 0, 0, 'full', '1200', '60', 'full', '1100', 0, '#03AEE2', 0.5, 'border-bottom', '5,5,5,5', 0, '10,40', '#000000', 0.5, '#FFFFFF', 0, '#F0F0F0', 'vertical', 0.0, '#FFFFFF', 'underline', 0, '#F0F0F0', 'vertical', 0.0, '20', '20', 'horizontal', '200', 'show', 0, 'click', '300', 1, 0, 'http://digital-aquitaine.com/wp-content/uploads/2015/10/digital-aquitaine-300x300.jpg', '80', '60', '#34495e', '#5dade2', '14', 'px', 'normal', 'underline', '#888888', '#888888', 1.0, 1, 1.0, '#F2F2F2', 'full', 0, 1.0, '#F0F0F0', 'small', '', 1, '#000', 0, 0.5, '#888888', 'Open Sans', '#34495e', '#5dade2', '14', 'px', 'normal', 'none', 'underline', '9999', 0, 'hero_red', 'medium', '#888888', '#DDDDDD', 1, '768', '992', '993', '0', '10', '10', 0, '', 'left', 'repeat', 0x23686d656e755f6c6f61645f31202e686d656e755f737562203e20756c203e206c69202e686d656e755f737562207b0a2f2a6c6566743a2031323070783b2a2f0a7d0a23686d656e755f6c6f61645f31202e686d656e755f737562203e20756c203e206c69203e2061203e202e686d656e755f77726170207b0a20202020646973706c61793a20696e6c696e652d626c6f636b3b0a2020202070616464696e673a203137707820313470782031307078203070783b0a202020206d617267696e3a20303b0a7d, '0', '#888888', '2016-01-20 19:23:09', '2016-07-01 17:38:38', 0),
    (2, 2, 1, '', '', '', '_self', '80', 0, '', '80', 0, 1, 1, 0, 'full', '1200', '80', 'fixed', '1100', 0, '#FFF', 0.5, 'border-bottom', '5,5,5,5', 0, '10,40', '#000000', 0.5, '#FFFFFF', 0, '#F0F0F0', 'vertical', 1.0, '#F0F0F0', 'background', 0, '#F0F0F0', 'vertical', 1.0, '10', '10', 'horizontal', '200', 'fade', 1000, 'click', '300', 0, 0, '', '80', '60', '#888888', '#888888', '12', 'px', 'normal', 'underline', '#888888', '#888888', 1.0, 0, 1.0, '#F0F0F0', 'small', 0, 1.0, '#F0F0F0', 'small', 'Menu', 1, '#000', 0, 0.5, '#888888', 'Open Sans', '#888888', '#888888', '12', 'px', 'normal', 'none', 'underline', '9999', 0, 'hero_red', 'medium', '#888888', '#DDDDDD', 1, '768', '992', '1200', '0', '10', '10', 0, '', 'left', 'repeat', '', '0', '#888888', '2017-01-11 10:24:47', NULL, 0);
     
    --
    -- Index pour les tables exportées
    --
     
    --
    -- Index pour la table `wp_hmenu_main_styles`
    --
    ALTER TABLE `wp_hmenu_main_styles`
      ADD PRIMARY KEY (`mainStyleId`),
      ADD KEY `hmenu_main_styles_menuId_1821200116_FK_idx` (`menuId`);
     
    --
    -- AUTO_INCREMENT pour les tables exportées
    --
     
    --
    -- AUTO_INCREMENT pour la table `wp_hmenu_main_styles`
    --
    ALTER TABLE `wp_hmenu_main_styles`
      MODIFY `mainStyleId` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=3;
    --
    -- Contraintes pour les tables exportées
    --
     
    --
    -- Contraintes pour la table `wp_hmenu_main_styles`
    --
    ALTER TABLE `wp_hmenu_main_styles`
      ADD CONSTRAINT `hmenu_main_styles_menuId_1821200116_FK` FOREIGN KEY (`menuId`) REFERENCES `wp_hmenu_menu` (`menuId`) ON DELETE NO ACTION ON UPDATE NO ACTION;
     
    /*!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 */;

    Je ne comprend pas l'erreur, d'après ce que j'ai compris c'est lié à la ligne 175 avec FOREIGN KEY, mais je ne comprend pas à quoi cette clé correspond et pourquoi il est impossible de l'ajouter:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    ALTER TABLE `wp_hmenu_main_styles`
      ADD CONSTRAINT `hmenu_main_styles_menuId_1821200116_FK` FOREIGN KEY (`menuId`) REFERENCES `wp_hmenu_menu` (`menuId`) ON DELETE NO ACTION ON UPDATE NO ACTION;
    Merci pour votre aide.

  2. #2
    Membre du Club
    Homme Profil pro
    Auditeur informatique
    Inscrit en
    Septembre 2015
    Messages
    35
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Auditeur informatique

    Informations forums :
    Inscription : Septembre 2015
    Messages : 35
    Points : 42
    Points
    42
    Par défaut
    Problème résolu, il faut importer la table parent avant

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. ERROR 1215 cannot add foreign key constraint
    Par momjunior dans le forum Requêtes
    Réponses: 4
    Dernier message: 24/06/2016, 15h23
  2. Réponses: 13
    Dernier message: 27/08/2015, 17h46
  3. Réponses: 4
    Dernier message: 14/06/2015, 14h44
  4. Réponses: 3
    Dernier message: 28/11/2011, 17h26
  5. Réponses: 0
    Dernier message: 12/12/2007, 21h10

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo