-1

Setting up a database in PHPMyAdmin and i have two tables, Foo and Bar. I want to use the Primary Key from Foo as a Foreign Key in Bar, but when i go to the relational view it says "No index defined!". Any ideas why?

Also, if i set this up, does that mean that as an Foreign Key, Foo will have its data auto imported and updated to Bar every time a new row is added?

Naftali
  • 144,921
  • 39
  • 244
  • 303
amartin94
  • 505
  • 3
  • 19
  • 35
  • Is your database engine InnoDB? Read this http://stackoverflow.com/questions/459312/setting-up-foreign-keys-in-phpmyadmin – Angel Doza Sep 18 '13 at 14:56

1 Answers1

2

i suppose you have to create a foo_id field in Bar that you will use as the foreign key. and you will have to update this field with the correct ids because it will probably complain when you will try to declare the field as a foreign key.

and data are not automatically updated. by declaring the foreign key as you suggest, it will just add some constraints: you won't be able, for example, to insert in Bar table a row with an non existent foo_id.

d34n5
  • 1,308
  • 10
  • 18