In this previous article you were introduced to MySQL Workbench, which essentially is a pretty great app to work with data modelling for MySQL databases.
In MySQL you can work with different indexes, keys and contraints, which are tools that help you build and maintain logical relationships between entries and tune your database for performance. One of those is the foreign key, which is automatically added to rows when using the relations functionality in MySQL workbench.
What are foreign keys
If you are used to manually create your database on your hosting account, for example using phpMyAdmin or similar, you might not create foreign keys. Their purpose is to indicate how a given row relates to a row – usually the ID – in another table. This is useful when having relations between records. For example every User has an Address, every Address has a Country etc. Those keys can be added, but it’s not required. Furthermore actions and contrainsts can be added if you wish.
What does Workbench do with foreign keys
The Workbench app exports the SQL for your data model including foreign keys by default. This might lead to unexpected behaviour, if your are not intending to use them, or simply are unfamiliar with them. For those of you who don’t care about foreign key constraints, you can simply remove them from the exported SQL, by selecting the proper checkbox right before exporting with Workbench.
So you can still use the nice visual modelling tools of Workbench, but export the SQL without the foreign keys.
No comments yet (leave a comment)