Mysql 添加多列和外键

Mysql 添加多列和外键,mysql,sql,foreign-keys,Mysql,Sql,Foreign Keys,我是结构化查询语言的初学者。我想添加具有不同外键的多列。如示例所示: drop schema humman; create schema humman; CREATE TABLE humman.father ( id int not null auto_increment, firstname varchar(200) not null, primary key(id) ); create table humman.mather( id int not null auto_incremen

我是结构化查询语言的初学者。我想添加具有不同外键的多列。如示例所示:

drop schema humman;

create schema humman;

CREATE TABLE humman.father (
id int not null auto_increment,
firstname varchar(200) not null,
primary key(id)
);

create table humman.mather(
id int not null auto_increment,
FirstName varchar(200),
primary key(id)
);

CREATE TABLE humman.child (
id int not null auto_increment,
firstname varchar(200) not null,
primary key(id)
);

use `humman`;

alter table humman.child 
ADD `parentId` int ,
ADD `motherId` int,
ADD  foreign key (`parentId`) references father(`id`),
ADD foreign key (`motherId`) references mother(`id`);
错误代码:1215无法添加外键约束


您的代码很好,除了输入错误,您在第二个表定义中将“mother”拼写为“mather”

create table humman.mather(
id int not null auto_increment,
FirstName varchar(200),
primary key(id)
);

纠正这一点,它应该会起作用。

不是母亲而是母亲