0

I`m a beginner in structured query language . I want to add multi columns with different foreign key.Like the example:

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`);

Error code: 1215 Cannot add foreign key CONSTRAINT

1
  • not mather but mother Commented Jun 10, 2018 at 22:13

1 Answer 1

1

Your code is good except for a typo, you spelt "mother" as "mather" in your second table definition;

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

correct that and it should work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.