How do I insert into
in a table where there is an FK?
example this is my structure
Pessoa
ID (primary key)
nome varchar(20)
id_endereco int not null (foreign key)
_______________________________________
endereco
ID (primary key)
rua varchar(50)
_______________________________________
In SQL I did
create table endereco (
ID int primary key NOT NULL,
rua varchar(50)
);
create table pessoa (
ID int primary key NOT NULL,
nome varchar(50) NOT NULL,
id_endereco int NOT NULL,
CONSTRAINT fk_idendereco FOREIGN KEY(id_endereco) REFERENCES pessoa(ID)
)
Then in the activity ask me, add 20 people ... the problem is that when I use "insert into person" I can not add the 20 people because of the foreign key, if I did not have it, I could get it right .. but as it exists in the person table, that error appears. >
Is there any way I can add to the person table, with nothing in the address? if not, what do I do?
insert into pessoa (id,nome,id_endereco)
values (1, "Jo Legendary", 1)