File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -558,10 +558,19 @@ func (info *FKInfo) RefColumns() []*ColumnInfo {
558
558
559
559
// RefUniqueIndex returns the referenced unique index.
560
560
// NOTE: It only returns unique index that have exactly the same group of columns as the referenced columns.
561
- // See: https://dev.mysql.com/doc/refman/5.6/en/create-table-foreign-keys.html
562
- // InnoDB permits a foreign key to reference any column or group of columns. However, in the referenced table,
563
- // there must be an index where the referenced columns are listed as the first columns in the same order.
564
- // NDB requires an explicit unique key (or primary key) on any column referenced as a foreign key.
561
+ //
562
+ // By SQL standard, the referenced columns should be a primary key or unique key of the referenced table
563
+ // to uniquely identify a row. But
564
+ //
565
+ // InnoDB allows a foreign key constraint to reference a non-unique key.
566
+ // This is an InnoDB extension to standard SQL.
567
+ //
568
+ // However
569
+ //
570
+ // The handling of foreign key references to nonunique keys or keys that contain NULL values
571
+ // is not well defined (...) You are advised to use foreign keys that reference only UNIQUE
572
+ // (including PRIMARY) and NOT NULL keys.
573
+ //
565
574
func (info * FKInfo ) RefUniqueIndex () * IndexInfo {
566
575
if info == nil {
567
576
return nil
You can’t perform that action at this time.
0 commit comments