MySQL Cannot Add Foreign Key Constraint

后端 未结 22 1827
时光取名叫无心
时光取名叫无心 2020-11-22 08:35

So I\'m trying to add Foreign Key constraints to my database as a project requirement and it worked the first time or two on different tables, but I have two tables on which

22条回答
  •  礼貌的吻别
    2020-11-22 09:05

    For me it was - you can't omit prefixing the current DB table if you create a FK for a non-current DB referencing the current DB:

    USE currrent_db;
    ALTER TABLE other_db.tasks ADD CONSTRAINT tasks_fk FOREIGN KEY (user_id) REFERENCES currrent_db.users (id);
    

    If I omit "currrent_db." for users table, I get the FK error. Interesting that SHOW ENGINE INNODB STATUS; shows nothing in this case.

提交回复
热议问题