我不能 select 列来指定外键
I can't select a column to specify a foreign key
我想做的很简单。 Select 列(我的外键)然后指定引用的列。
但似乎 MySql workbench 有一个错误。我不能 select 我的外键。有谁知道如何解决这个问题?
.
Mysql 版本 > 8.0.12
Does anyone know how to solve this?
一般规则是两列必须是同一类型并且引用的列必须被索引(例如主键)。
如果您分享 SHOW CREATE TABLE <table>
两个表格,我可以提供更多信息。
这里是 official documentation 的所有要求列表:
Parent and child tables must use the same storage engine, and they
cannot be defined as temporary tables.
Creating a foreign key constraint requires at least one of the SELECT,
INSERT, UPDATE, DELETE, or REFERENCES privileges on the parent table
as of 5.6.22.
Corresponding columns in the foreign key and the referenced key must
have similar data types. The size and sign of integer types must be
the same. The length of string types need not be the same. For
nonbinary (character) string columns, the character set and collation
must be the same.
MySQL supports foreign key references between one column and another
within a table. (A column cannot have a foreign key reference to
itself.) In these cases, a “child table record” refers to a dependent
record within the same table.
MySQL requires indexes on foreign keys and referenced keys so that
foreign key checks can be fast and not require a table scan. In the
referencing table, there must be an index where the foreign key
columns are listed as the first columns in the same order. Such an
index is created on the referencing table automatically if it does not
exist. This index might be silently dropped later if you create
another index that can be used to enforce the foreign key constraint.
index_name, if given, is used as described previously.
InnoDB permits a foreign key to reference any index column or group of
columns. However, in the referenced table, there must be an index
where the referenced columns are the first columns in the same order.
Hidden columns that InnoDB adds to an index are also considered (see
Section 14.6.2.1, “Clustered and Secondary Indexes”).
NDB requires an explicit unique key (or primary key) on any column
referenced as a foreign key. InnoDB does not, which is an extension of
standard SQL.
Index prefixes on foreign key columns are not supported. Consequently,
BLOB and TEXT columns cannot be included in a foreign key because
indexes on those columns must always include a prefix length.
InnoDB does not currently support foreign keys for tables with
user-defined partitioning. This includes both parent and child tables.
This restriction does not apply for NDB tables that are partitioned by
KEY or LINEAR KEY (the only user partitioning types supported by the
NDB storage engine); these may have foreign key references or be the
targets of such references.
A table in a foreign key relationship cannot be altered to use another
storage engine. To change the storage engine, you must drop any
foreign key constraints first.
我想做的很简单。 Select 列(我的外键)然后指定引用的列。 但似乎 MySql workbench 有一个错误。我不能 select 我的外键。有谁知道如何解决这个问题?
Mysql 版本 > 8.0.12
Does anyone know how to solve this?
一般规则是两列必须是同一类型并且引用的列必须被索引(例如主键)。
如果您分享 SHOW CREATE TABLE <table>
两个表格,我可以提供更多信息。
这里是 official documentation 的所有要求列表:
Parent and child tables must use the same storage engine, and they cannot be defined as temporary tables.
Creating a foreign key constraint requires at least one of the SELECT, INSERT, UPDATE, DELETE, or REFERENCES privileges on the parent table as of 5.6.22.
Corresponding columns in the foreign key and the referenced key must have similar data types. The size and sign of integer types must be the same. The length of string types need not be the same. For nonbinary (character) string columns, the character set and collation must be the same.
MySQL supports foreign key references between one column and another within a table. (A column cannot have a foreign key reference to itself.) In these cases, a “child table record” refers to a dependent record within the same table.
MySQL requires indexes on foreign keys and referenced keys so that foreign key checks can be fast and not require a table scan. In the referencing table, there must be an index where the foreign key columns are listed as the first columns in the same order. Such an index is created on the referencing table automatically if it does not exist. This index might be silently dropped later if you create another index that can be used to enforce the foreign key constraint. index_name, if given, is used as described previously.
InnoDB permits a foreign key to reference any index column or group of columns. However, in the referenced table, there must be an index where the referenced columns are the first columns in the same order. Hidden columns that InnoDB adds to an index are also considered (see Section 14.6.2.1, “Clustered and Secondary Indexes”).
NDB requires an explicit unique key (or primary key) on any column referenced as a foreign key. InnoDB does not, which is an extension of standard SQL.
Index prefixes on foreign key columns are not supported. Consequently, BLOB and TEXT columns cannot be included in a foreign key because indexes on those columns must always include a prefix length.
InnoDB does not currently support foreign keys for tables with user-defined partitioning. This includes both parent and child tables.
This restriction does not apply for NDB tables that are partitioned by KEY or LINEAR KEY (the only user partitioning types supported by the NDB storage engine); these may have foreign key references or be the targets of such references.
A table in a foreign key relationship cannot be altered to use another storage engine. To change the storage engine, you must drop any foreign key constraints first.