クライアントやサイト テーブルにレコードを追加しようとすると、次のエラーが発生します。
スキーマの作成に失敗しました: 子行を追加または更新できません: 外部キー制約が失敗しました (
db_2_6ceaf
.client
, CONSTRAINTclient2offer
FOREIGN KEY (clientID
) REFERENCESoffer_to_client
(clientID
) ON DELETE NO ACTION ON UPDATE NO ACTION):
SQL:
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='TRADITIONAL,ALLOW_INVALID_DATES';
-- -----------------------------------------------------
-- Table `offer_to_category`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `offer_to_category` (
`offerID` INT UNSIGNED NOT NULL ,
`categoryID` INT UNSIGNED NOT NULL ,
INDEX `offer_to_category` (`offerID` ASC, `categoryID` ASC) ,
INDEX `o2c_categoryID` (`categoryID` ASC) )
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `offer_to_client`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `offer_to_client` (
`offerID` INT UNSIGNED NOT NULL ,
`clientID` INT UNSIGNED NOT NULL ,
INDEX `offer_to_client` (`offerID` ASC, `clientID` ASC) ,
INDEX `o2cl_clientID` (`clientID` ASC) )
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `offer`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `offer` (
`offerID` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`offerName` VARCHAR(255) NULL ,
`offerDescription` LONGTEXT NULL ,
`offerAction` TEXT NULL ,
`offerStart` BIGINT NULL ,
`offerEnd` BIGINT NULL ,
`offerStatus` TINYINT(1) NULL ,
PRIMARY KEY (`offerID`) ,
CONSTRAINT `offer2cat`
FOREIGN KEY (`offerID` )
REFERENCES `offer_to_category` (`offerID` )
ON DELETE CASCADE
ON UPDATE NO ACTION,
CONSTRAINT `offer2client`
FOREIGN KEY (`offerID` )
REFERENCES `offer_to_client` (`offerID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `category`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `category` (
`categoryID` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`categoryName` VARCHAR(255) NULL ,
`categoryDescription` LONGTEXT NULL ,
`categoryStatus` TINYINT(1) NULL ,
PRIMARY KEY (`categoryID`) ,
CONSTRAINT `cat2offer`
FOREIGN KEY (`categoryID` )
REFERENCES `offer_to_category` (`categoryID` )
ON DELETE CASCADE
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `user`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `user` (
`userID` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`clientID` INT UNSIGNED NOT NULL ,
`userEmail` VARCHAR(255) NULL ,
`userFirstName` VARCHAR(255) NULL ,
`userLastName` VARCHAR(255) NULL ,
`userRegistered` BIGINT NULL ,
`userStatus` TINYINT(1) NULL ,
PRIMARY KEY (`userID`) ,
INDEX `client` (`clientID` ASC, `userEmail` ASC) )
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `client`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `client` (
`clientID` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`siteID` INT UNSIGNED NOT NULL ,
`clientName` VARCHAR(255) NULL ,
`clientDescription` LONGTEXT NULL ,
`clientUrl` LONGTEXT NULL ,
`clientStatus` TINYINT(1) NULL ,
PRIMARY KEY (`clientID`) ,
INDEX `clientsiteid` (`siteID` ASC) ,
CONSTRAINT `client2offer`
FOREIGN KEY (`clientID` )
REFERENCES `offer_to_client` (`clientID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `client2user`
FOREIGN KEY (`clientID` )
REFERENCES `user` (`clientID` )
ON DELETE CASCADE
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `admins`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `admins` (
`adminID` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`adminName` VARCHAR(255) NULL ,
`adminEmail` LONGTEXT NULL ,
`adminUsername` VARCHAR(255) NULL ,
`adminStatus` TINYINT(1) NULL ,
PRIMARY KEY (`adminID`) )
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `site`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `site` (
`siteID` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`siteName` VARCHAR(255) NULL ,
`siteURL` LONGTEXT NULL ,
`siteStyles` LONGTEXT NULL ,
`siteImages` LONGTEXT NULL ,
`sitesStatus` TINYINT(1) NULL ,
PRIMARY KEY (`siteID`) ,
CONSTRAINT `site2client`
FOREIGN KEY (`siteID` )
REFERENCES `client` (`siteID` )
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;
-- -----------------------------------------------------
-- Data for table `client`
-- -----------------------------------------------------
START TRANSACTION;
INSERT INTO `client` (`clientID`, `siteID`, `clientName`, `clientDescription`, `clientUrl`, `clientStatus`) VALUES (NULL, 1, 'Weight Watchers', 'Weight Watchers microsite', 'weightwachers', 1);
INSERT INTO `client` (`clientID`, `siteID`, `clientName`, `clientDescription`, `clientUrl`, `clientStatus`) VALUES (NULL, 1, 'A Uni', NULL, NULL, 1);
INSERT INTO `client` (`clientID`, `siteID`, `clientName`, `clientDescription`, `clientUrl`, `clientStatus`) VALUES (NULL, 2, 'Ollie Biz', '', NULL, 1);
INSERT INTO `client` (`clientID`, `siteID`, `clientName`, `clientDescription`, `clientUrl`, `clientStatus`) VALUES (NULL, 2, 'Ollie Uni', NULL, 'ollieuni', 1);
COMMIT;
-- -----------------------------------------------------
-- Data for table `site`
-- -----------------------------------------------------
START TRANSACTION;
INSERT INTO `site` (`siteID`, `siteName`, `siteURL`, `siteStyles`, `siteImages`, `sitesStatus`) VALUES (1, 'We Love Rewards', 'http://www.weloverewards.co.uk', NULL, NULL, 1);
INSERT INTO `site` (`siteID`, `siteName`, `siteURL`, `siteStyles`, `siteImages`, `sitesStatus`) VALUES (2, 'Ollie Rewards', 'http://www.olliesrewards.co.uk', NULL, NULL, 1);
COMMIT;