mysql - child tables and foreign keys -


i know there have been myriads of questions concerning primary , foreign keys. looking through them, cannot seem find simple answer question. understanding of primary , foreign keys foreign key column designated in child table refers primary key column in parent table. correct, or have backwards? if indeed correct, trying find out why having difficulty creating foreign key in child table such:

salesorders.sonumber (pk) < customer.sonumber (fk)

i using navicat mariadb (same mysql) , error is:

1452 - cannot add or update child row: foreign key constraint fails ('customer_orders','#sql7a8_3'; constraint 'sonumber' foreign key ('sonumber') references 'salesorder' ('sonumber') on delete no action on update cascade)

customer_orders database name. naming foreign key 'sonumber' same column name in child table (customer) , parent table (salesorders). incorrect? should give foreign key name?

gitpicker

the foreign key should have own unique name, yes. sonumber_fk or similar simple naming schema.

you need make sure every entry in foreign key column has corresponding entry in referenced table, otherwise not able create foreign key.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -