MySQL Forums
Forum List  »  French

probleme BDD liaison
Posted by: lidian manoha
Date: January 16, 2019 04:19AM

exemple je souhaite afficher un menu avec categorie material sous categorie bois et des tags Wood
Bonjour alors voila pour faire simple je suis trés débutant en sql et donc je souhaite creer une basse avec un item et qui s'affiche avec une categorie et une sous categorie et avec des tags

j'ai créer une base de donnée avec mysql workbench et quand je l'importe j'ai une erreur de creation (Errcode: 150 "Foreign key constraint is incorrectly formed")

alors je mis prend peu être mal voici le script merci de votre aide

-- MySQL Script generated by MySQL Workbench
-- Wed Jan 16 11:14:20 2019
-- Model: New Model Version: 1.0
-- MySQL Workbench Forward Engineering

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

-- -----------------------------------------------------
-- Schema ressource
-- -----------------------------------------------------

-- -----------------------------------------------------
-- Schema ressource
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `ressource` DEFAULT CHARACTER SET utf8 ;
USE `ressource` ;

-- -----------------------------------------------------
-- Table `ressource`.`menbers`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `ressource`.`menbers` (
`id` INT NOT NULL AUTO_INCREMENT,
`password` VARCHAR(255) NOT NULL,
`email` VARCHAR(255) NOT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `ressource`.`items`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `ressource`.`items` (
`id` INT NOT NULL AUTO_INCREMENT,
`title` VARCHAR(255) NULL,
`description` VARCHAR(255) NULL,
`categories_id` INT NOT NULL,
`subcategories_id` INT NOT NULL,
`tag_id` INT NOT NULL,
`images` VARCHAR(255) NOT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `ressource`.`categories`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `ressource`.`categories` (
`name` VARCHAR(255) NOT NULL,
`subcategories_id` INT NOT NULL,
`id` INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`),
CONSTRAINT `fk_categories_items1`
FOREIGN KEY (`id`)
REFERENCES `ressource`.`items` (`categories_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `ressource`.`subcategories`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `ressource`.`subcategories` (
`id` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `fk_subcategories_categories1`
FOREIGN KEY (`id`)
REFERENCES `ressource`.`categories` (`subcategories_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `ressource`.`tags`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `ressource`.`tags` (
`id` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL,
`items_id` INT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `fk_tags_items1`
FOREIGN KEY (`id`)
REFERENCES `ressource`.`items` (`tag_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;


SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;

Options: ReplyQuote


Subject
Views
Written By
Posted
probleme BDD liaison
544
January 16, 2019 04:19AM
285
January 17, 2019 04:17PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.