所以我有,表的課程:SQL錯誤:1364字段 'XXXX' 沒有默認值
CREATE TABLE IF NOT EXISTS `AppDziennik`.`courses` (
`id_course` INT NOT NULL AUTO_INCREMENT ,
`name` VARCHAR(80) NOT NULL ,
`teachers_id_teacher` INT NOT NULL ,
`end_date` DATE NULL ,
`about` VARCHAR(255) NULL ,
`start_date` DATE NULL ,
PRIMARY KEY (`id_course`) ,
UNIQUE INDEX `id_course_UNIQUE` (`id_course` ASC) ,
CONSTRAINT `fk_courses_teachers1`
FOREIGN KEY (`teachers_id_teacher`)
REFERENCES `AppDziennik`.`teachers` (`id_teacher`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
和第二臺
CREATE TABLE IF NOT EXISTS `AppDziennik`.`teachers` (
`id_teacher` INT NOT NULL AUTO_INCREMENT ,
`name` VARCHAR(45) NOT NULL ,
`surname` VARCHAR(45) NOT NULL ,
`about` VARCHAR(255) NULL ,
`id_class` INT NULL ,
`rank` VARCHAR(45) NULL ,
`logins_id_login` INT NOT NULL ,
PRIMARY KEY (`id_teacher`) ,
INDEX `fk_teachers_classes1_idx` (`id_class` ASC) ,
INDEX `fk_teachers_logins1_idx` (`logins_id_login` ASC) ,
CONSTRAINT `fk_teachers_classes1`
FOREIGN KEY (`id_class`)
REFERENCES `AppDziennik`.`classes` (`id_class`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_teachers_logins1`
FOREIGN KEY (`logins_id_login`)
REFERENCES `AppDziennik`.`logins` (`id_login`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
當我作出這樣的插入
insert into appdziennik.courses (name, id_teacher, about, start_date, end_date) values ("Math",'7',"Math",'2013-08-01','2014-06-29');
我得到那個錯誤:
Error Code: 1364. Field 'teachers_id_teacher' doesn't have a default value
我犯了什麼錯誤?我怎麼能解決它。
在'courses'列名稱似乎是'teachers_id_teacher'而不是'id_teacher' - 錯字在這個問題上或在您的代碼? –
我太信任我的MySQL WorkBench自動生成代碼。它在我創建時調用這樣的列(teachers_id_teacher)。無論如何THX – Aku