• For some reason I am unable to create foreign keys within my databases.
    The following code returns the error ‘Failed to create table.’

    CREATE TABLE Orders
    (
    O_Id int NOT NULL,
    OrderNo int NOT NULL,
    P_Id int,
    PRIMARY KEY (O_Id),
    FOREIGN KEY (P_Id) REFERENCES Persons(P_Id)
    );

    Any help is greatly appreciated.

Viewing 1 replies (of 1 total)
  • Plugin Author ka2

    (@ka2)

    Sorry for my late reply.

    There are several reasons if you cannot create foreign key, and they will be mentioned below.

    1. The DB engine of “Persons” table as reference table is not “InnoDB”, or The “Orders” is not “InnoDB”.
    2. The “P_Id” column in “Persons” table as reference table does not have index.
    3. The “P_Id” column of both “Persons” table and “Orders” table does not have same column type.

    Please try to check items above.

    Also, if you checked the “Debug Mode” at “plugin options” menu, you can see detail why failed the table creation on the “Debug” tab.

    Thank you,

Viewing 1 replies (of 1 total)
  • The topic ‘Can’t Create Foreign Keys’ is closed to new replies.