xoops forums

luciorota

Module Developer
Posted on: 2018/12/3 15:54
luciorota
luciorota (Show more)
Module Developer
Posts: 185
Since: 2007/4/20
#1

FOREIGN KEY

Hi everybody
How can I set FOREIGN KEY on module tables when I use Xoops modules installation procedure?
Thanks
Lucio

geekwright

Quite a regular
Posted on: 2018/12/4 17:38
geekwright
geekwright (Show more)
Quite a regular
Posts: 253
Since: 2010/10/15
#2

Re: FOREIGN KEY

Since the SqlUtility class doesn't recognize the table name in the REFERENCES clause, you will have to add the constraint outside of the module's mysql.sql file.

I would suggest generating and running the SQL to perform an "ALTER TABLE ... ADD FOREIGN KEY ..." inside the onInstall file's xoops_module_install_dirname() function.

Longer term, this should become a non-issue as we progress toward schema definitions rather than SQL for table creation.