我的数据库看起来:
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';
CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET utf8 ;
USE `mydb` ;
CREATE TABLE IF NOT EXISTS `mydb`.`contacts` (
`idcontact` INT NOT NULL AUTO_INCREMENT,
`phone` VARCHAR(45) NULL,
`email` VARCHAR(45) NULL,
PRIMARY KEY (`idcontact`))
ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS `mydb`.`adresses` (
`idadress` INT NOT NULL AUTO_INCREMENT,
`city` VARCHAR(45) NULL,
`street` VARCHAR(45) NULL,
`street_number` VARCHAR(45) NULL,
PRIMARY KEY (`idadress`))
ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS `mydb`.`employees` (
`idemployee` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(45) NULL,
`surname` VARCHAR(45) NULL,
`adresses_idadress` INT NOT NULL,
`contacts_idcontact` INT NOT NULL,
PRIMARY KEY (`idemployee`),
INDEX `fk_employees_adresses_idx` (`adresses_idadress` ASC),
INDEX `fk_employees_contacts1_idx` (`contacts_idcontact` ASC),
CONSTRAINT `fk_employees_adresses`
FOREIGN KEY (`adresses_idadress`)
REFERENCES `mydb`.`adresses` (`idadress`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_employees_contacts1`
FOREIGN KEY (`contacts_idcontact`)
REFERENCES `mydb`.`contacts` (`idcontact`)
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;
然后我插入表格地址和联系人,如下所示:
insert into mydb.contacts(phone,email) values ('123123123','email@gmail.com');
insert into mydb.adresses(city,street,street_number) values ('London','28th Street','13');
And next I want to insert into employees:
insert into mydb.employees(name,surname) values ('Jack','Reaper');
And i receive this error:
insert into mydb.employees(name,surname) values ('Jack','Reaper');
)在更新时不执行任何操作“
我需要做些什么来修复它?
答案 0 :(得分:0)
在员工表上的插入中,您还必须提供address_isaddress和contact_idcontact。没有它,插入就不会通过。