2012-09-05 47 views
-2

我得到一個不能添加或更新子行,外鍵約束失敗的MySQL PHP

「不能添加或更新子行,外鍵約束失敗 (smarturbiapois,約束fk_pois_cities1。 FOREIGN KEY (city)參考文獻citiesid)ON DELETE NO ACTION ON UPDATE NO ACTION)(1509)」

,我不知道爲什麼。

我的表是通過MySQL工作臺5.2生成的,如果你需要的表的其餘部分讓我知道:

-- ----------------------------------------------------- 
-- Table `smarturbia`.`cities` 
-- ----------------------------------------------------- 
DROP TABLE IF EXISTS `smarturbia`.`cities` ; 

CREATE TABLE IF NOT EXISTS `smarturbia`.`cities` (
    `id` BIGINT(11) NOT NULL AUTO_INCREMENT , 
    `published` VARCHAR(1) NOT NULL DEFAULT '0' , 
    `open` VARCHAR(1) NOT NULL DEFAULT '0' , 
    `path` VARCHAR(25) NOT NULL DEFAULT 'taxi' , 
    `key` VARCHAR(50) NOT NULL , 
    `world` VARCHAR(10) NOT NULL DEFAULT 'earth' , 
    `name` VARCHAR(50) NOT NULL , 
    `description` VARCHAR(250) NULL DEFAULT NULL , 
    `logo` VARCHAR(250) NULL DEFAULT NULL , 
    `footer` VARCHAR(250) NOT NULL DEFAULT '/taxi/assets/img/taxi_smarturbia_image_default.png' , 
    `footer_large` VARCHAR(250) NOT NULL , 
    `leftpub` VARCHAR(50) NOT NULL , 
    `rightpub` VARCHAR(50) NOT NULL , 
    `model` VARCHAR(250) NOT NULL , 
    `modelxscale` FLOAT NULL DEFAULT '1' , 
    `modelyscale` FLOAT NULL DEFAULT '1' , 
    `modelzscale` FLOAT NULL DEFAULT '1' , 
    `wheelmodelxscale` FLOAT NULL DEFAULT '1' , 
    `wheelmodelyscale` FLOAT NULL DEFAULT '1' , 
    `wheelmodelzscale` FLOAT NULL DEFAULT '1' , 
    `allwheels` VARCHAR(250) NULL DEFAULT NULL , 
    `frontleftwheel` VARCHAR(250) NULL DEFAULT NULL , 
    `frontrightwheel` VARCHAR(250) NULL DEFAULT NULL , 
    `rearleftwheel` VARCHAR(250) NULL DEFAULT NULL , 
    `rearrightwheel` VARCHAR(250) NULL DEFAULT NULL , 
    `axisdistance` FLOAT NOT NULL DEFAULT '2.5' , 
    `wheelsdistance` FLOAT NULL DEFAULT '1' , 
    `wheelsheight` FLOAT NULL DEFAULT '1' , 
    `kms` FLOAT NULL DEFAULT '0' , 
    `maxspeed` FLOAT NULL DEFAULT '160' , 
    `accel` FLOAT NULL DEFAULT '25' , 
    `accelstep` FLOAT NULL DEFAULT '25' , 
    `minaccelstep` FLOAT NULL DEFAULT '5' , 
    `maxrevspeed` FLOAT NULL DEFAULT '30' , 
    `decel` FLOAT NULL DEFAULT '90' , 
    `gravity` FLOAT NULL DEFAULT '70' , 
    `camheight` FLOAT NULL DEFAULT '5' , 
    `camtilt` FLOAT NULL DEFAULT '90' , 
    `traildistance` FLOAT NULL DEFAULT '15' , 
    `mass` FLOAT NULL DEFAULT '3000' , 
    `vehicleagility` FLOAT NULL DEFAULT '0.0005' , 
    `suspensionstiffness` FLOAT NULL DEFAULT '0.5' , 
    `suspensionrestlength` FLOAT NULL DEFAULT '0.5' , 
    `suspensiondamping` FLOAT NULL DEFAULT '-0.15' , 
    `suspensiondeltatime` FLOAT NULL DEFAULT '0.25' , 
    `turnspeedmin` FLOAT NULL DEFAULT '20' , 
    `turnspeedmax` FLOAT NULL DEFAULT '60' , 
    `speedmaxturn` FLOAT NULL DEFAULT '5' , 
    `speedminturn` FLOAT NULL DEFAULT '50' , 
    `steerroll` FLOAT NULL DEFAULT '-1' , 
    `rollspring` FLOAT NULL DEFAULT '0.5' , 
    `rollclamp` FLOAT NULL DEFAULT '50' , 
    `mapiconurl` VARCHAR(250) NULL DEFAULT NULL , 
    `vehicleshadow` VARCHAR(250) NULL DEFAULT NULL , 
    `vehiclesound` VARCHAR(250) NULL DEFAULT NULL , 
    `vehiclesoundtime` FLOAT NULL DEFAULT '150' , 
    `vehiclefastsound` VARCHAR(250) NULL DEFAULT NULL , 
    `vehiclefastsoundtime` FLOAT NULL DEFAULT '150' , 
    `backgroundsound` VARCHAR(250) NULL DEFAULT NULL , 
    `backgroundsoundtime` FLOAT NULL DEFAULT '150' , 
    `crashsound` VARCHAR(250) NULL DEFAULT NULL , 
    `crashsoundtime` FLOAT NULL DEFAULT '150' , 
    `vehicletype` VARCHAR(50) NULL DEFAULT 'car' , 
    `date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP , 
    PRIMARY KEY (`id`) , 
    INDEX `key` (`key` ASC)) 
ENGINE = InnoDB 
AUTO_INCREMENT = 153 
DEFAULT CHARACTER SET = latin1; 

-- ----------------------------------------------------- 
-- Table `smarturbia`.`pois` 
-- ----------------------------------------------------- 
DROP TABLE IF EXISTS `smarturbia`.`pois` ; 

CREATE TABLE IF NOT EXISTS `smarturbia`.`pois` (
    `id` BIGINT(20) NOT NULL AUTO_INCREMENT , 
    `city` BIGINT(11) NOT NULL , 
    `name` VARCHAR(50) NOT NULL , 
    `description` VARCHAR(250) NOT NULL , 
    `lat` DOUBLE NOT NULL , 
    `lon` DOUBLE NOT NULL , 
    `heading` FLOAT NULL DEFAULT '0' , 
    PRIMARY KEY (`id`) , 
    INDEX `fk_pois_cities1_idx` (`city` ASC) , 
    CONSTRAINT `fk_pois_cities1` 
    FOREIGN KEY (`city`) 
    REFERENCES `smarturbia`.`cities` (`id`) 
    ON DELETE NO ACTION 
    ON UPDATE NO ACTION) 
ENGINE = InnoDB 
AUTO_INCREMENT = 408 
DEFAULT CHARACTER SET = latin1; 
+1

這顯然來自於一個在執行INSERT或UPDATE查詢。你可以發佈它嗎? – Bgi

+0

數據有問題。首先修復數據。 – Devart

回答

2

插入值中,你的主鍵是defined..Then嘗試表在你有外鍵的表中插入...

我認爲你是在外鍵表中插入值而不插入具有主鍵的表中。 這是不推薦的,但你可以嘗試這

      set foreign_key_checks=0; 

要啓用外鍵檢查

     set foreign_key_checks=1; 
相關問題