Foreign keys in MySQL problem

Discussion in 'MySQL' started by feonix, Dec 2, 2008.

  1. #1
    Can anyone help me get around this error when trying to use user_id from PHPBB table phpbb_users as a foreign key in a new table?

    Here is my attempt to create the table...

    The error: ERROR 1005 (HY000): Can't create table 'forum.test_table' (errno: 150)

    And... the latest foreign key error...



    This error message is just over my head. What do I need to do to get this foreign key working?
     
    feonix, Dec 2, 2008 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Make sure the column data types match perfectly. int(11) is not int unsigned (11) etc. Make sure both tables use InnoDB storage. Make sure there is a unique index on phpbb_users (user_id). Make sure there isn't an existing foreign key violation in the user_id of the new table (wont be an issue if you're just creating it).

    Other than that, it should work.
     
    jestep, Dec 2, 2008 IP