Como configurar o relacionamento entre tabelas No phpMyAdmin

A questão que tenho é, quando crio uma tabela, por exemplo:table1 com as seguintes colunas:

customerIdCustomerNameAddressState

OndecustomerId é oPRIMARY KEY comAUTO_INCREMENT.

E depoistable2 por exemplo, com colunas:

purchaseIdcustomerIdproductcost

Onde oPRIMARY KEY épurchaseId e a chave estrangeira écustomerId detable1.

Isso deveria significar que eu já estabeleci uma relação entretable1 etable2 usando ocustomerId.

Ambas as tabelas estão inicialmente vazias, então eu escrevi este comando SQL:

INSERT INTO table1 (CustomerName,Address,State) VALUES('value1','value2','value3')

Isso funciona bem, mas quando tento inserir na tabela filho (table2) me diz:

ERRO uma restrição de chave estrangeira

Então, basicamente, o que eu quero fazer é inserir na tabela pai e depois na tabela filho para que ocustomerId aparece emtable2 (tabela filho) como uma chave estrangeira e corresponde acustomerId notable1 (Tabela pai).

TENHO QUE CRIAR AS DUAS MESAS PRIMEIRO SEM A CHAVE ESTRANGEIRA E TENTAR ESTABELECER UM RELACIONAMENTO. Continua dizendo que há uma restrição enquanto o relacionamento estiver lá.

questionAnswers(1)

yourAnswerToTheQuestion