首页 > 解决方案 > MySQL Workbench:如何将外键引用更改为与外表不同的字段?

问题描述

我有表 A,它使用外键(int)引用表 B。我希望表 A 中的所有条目都引用表 B 的name字段(varchar)。如何对表 A 中的所有条目进行此更改?

每当我调出列名和数据类型的列表时,在“列”选项卡中将外键更改为 varchar 都会出现错误,而将外键更改为引用 B 的名称而不是 B 的 id 则会出现错误:

Create foreign key: Selected column Name must be indexed and be of a compatible type for a Foreign Key to be created

标签: mysqlmysql-workbench

解决方案


推荐阅读