HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

How to create tables with foreign keys correctly?

Hello again!

As I said before, I'm creating an application (to create "Jams"), i'm trying to understand now the database structure file (creation scripts).
By now I have this for foreign keys:


    ->Column('UserID', 'int', FALSE, 'key')
    ->Column('GroupID', 'int', FALSE, 'key')
    ->Column('DateCreated', 'datetime', NULL)
    ->Column('DateUpdated', 'datetime', NULL)
    ->Column('IsPublic', 'tinyint(1)', '1')
    ->Set($Explicit, $Drop);

But I use also this when a FK is a PK member in another table:
->Column('GroupID', 'int', FALSE, array('primary', 'key'))

Although, in other applications I see they don't use "key" for FK's in some cases.

How's the better way to do it?

Thank you!

Off-topic: I ask under this category because I can't select "development", and I just upgraded to v2.2

Best Answer


Sign In or Register to comment.