mysql数据库填充数据出现问题,望赐教!
CREATE TABLE `managesystem`.`department_manager` (`dm_id` INT NOT NULL,
`user_id` VARCHAR(20) NOT NULL,
`dm_name` VARCHAR(20) NOT NULL,
`dp_id` INT NOT NULL,
`is_onjob` TINYINT NOT NULL,
`co_id` INT NOT NULL,
PRIMARY KEY (`dm_id`),
CONSTRAINT `user_id`
FOREIGN KEY ()
REFERENCES `managesystem`.`user` ()
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_bin;
Operation failed: There was an error while applying the SQL script to the database.Executing:
CREATE TABLE `managesystem`.`department_manager` (
`dm_id` INT NOT NULL,
`user_id` VARCHAR(20) NOT NULL,
`dm_name` VARCHAR(20) NOT NULL,
`dp_id` INT NOT NULL,
`is_onjob` TINYINT NOT NULL,
`co_id` INT NOT NULL,
PRIMARY KEY (`dm_id`),
CONSTRAINT `user_id`
FOREIGN KEY ()
REFERENCES `managesystem`.`user` ()
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_bin;
ERROR 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')
REFERENCES `managesystem`.`user` ()
ON DELETE NO ACTION
ON UPDATE ' at line 10
SQL Statement:
CREATE TABLE `managesystem`.`department_manager` (
`dm_id` INT NOT NULL,
`user_id` VARCHAR(20) NOT NULL,
`dm_name` VARCHAR(20) NOT NULL,
`dp_id` INT NOT NULL,
`is_onjob` TINYINT NOT NULL,
`co_id` INT NOT NULL,
PRIMARY KEY (`dm_id`),
CONSTRAINT `user_id`
FOREIGN KEY ()
REFERENCES `managesystem`.`user` ()
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_bin
本人是直接往表格里输属性和数据类型,没有手敲sql语句,想问现问题出在哪,该如何解决?不胜感激!
问题嘛,应该就是出在你的设置的外键(user_id VARCHAR
)和主键(dm_id INT
)的数据类型不匹配上。
不过自动生成的语句是挺怪的,在外键那小节缺失了外键列和主键列。题主用的是什么版本的 MySQL 和管理工具?
CREATE TABLE `department_manager` (`dm_id` INT NOT NULL,
`user_id` VARCHAR(20) NOT NULL,
`dm_name` VARCHAR(20) NOT NULL,
`dp_id` INT NOT NULL,
`is_onjob` TINYINT NOT NULL,
`co_id` INT NOT NULL,
PRIMARY KEY (`dm_id`),
CONSTRAINT `user_id`
FOREIGN KEY (user_id)
REFERENCES `user` (user_id)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_bin;
没有指定约束字段和被约束字段,
FOREIGN KEY (user_id)REFERENCES `user` (user_id)
后面指定下就可以了
回答
以上是 mysql数据库填充数据出现问题,望赐教! 的全部内容, 来源链接: utcz.com/a/113136.html