How do I set up Foreign Key references from db.xml?

I have several tables which reference each others' IDs.

I want those set up using foreign keys, so if I delete a row from a certain table without changing other tables' rows referencing that one, I'll get a error.

I want that done from db.xml, since that's how it's ought to be, isn't it?
So, how do I set up foreign key references from db.xml?

View Replies:
lunatik replied on at Permalink Reply
I've found out there's <constraints> tag available in db.xml, which is probably intended to solve my problem.

But does anybody knows the proper syntax?
I would be thankful for any example.
tbcrowe replied on at Permalink Reply
I have not used constraints with db.xml but the file format is documented for C5 here:
and more general information about the AXMLS format can be found here:
lunatik replied on at Permalink Reply
I solved my problem.

Here's a little tutorial if you're searching for the same thing (since there is little about it in the docs):

1. Check if your db engine is InnoDB (mysql default prior to version 5.5 is MyISAM).
Constratints only work with InnoDB

2. In your db.xml check that every field you want to be a Foreign Key has all the same attributes as it's reference field (if reference field is unsigned integer, your field should be too).

3. Add <constraints> tag to your field in db.xml
It should look like this:
<field name="user_id" type="I">
  <unsigned />
    , foreign key (user_id) references Users(uID)

Note the comma.

That's it.
piotrd replied on at Permalink Reply
Thanks, lunatik! After almost 4 years, your post is still useful. And Concrete5's documentation still sucks...