diff --git a/go/vt/schemadiff/schema.go b/go/vt/schemadiff/schema.go index df1e23f0ccc..3b42d6cf42d 100644 --- a/go/vt/schemadiff/schema.go +++ b/go/vt/schemadiff/schema.go @@ -444,6 +444,13 @@ func colTypeEqualForForeignKey(env *Environment, ct, pt *sqlparser.TableSpec, ch } func colCollationEqualForForeignKey(env *Environment, ct, pt *sqlparser.TableSpec, child, parent *sqlparser.ColumnType) bool { + isTextual := func(col *sqlparser.ColumnType) bool { + return charsetTypes[strings.ToLower(col.Type)] + } + if !isTextual(child) || !isTextual(parent) { + // irrelevant if columns are not textual + return true + } return *colCollation(env, ct, child) == *colCollation(env, pt, parent) } diff --git a/go/vt/schemadiff/schema_test.go b/go/vt/schemadiff/schema_test.go index c35cc224714..8a4f54269cd 100644 --- a/go/vt/schemadiff/schema_test.go +++ b/go/vt/schemadiff/schema_test.go @@ -412,6 +412,28 @@ func TestInvalidSchema(t *testing.T) { create table t13 (id int primary key, i int, key i_idx (i), constraint f1307 foreign key (i) references t11 (i)); `, }, + { + schema: ` + CREATE TABLE t1 (id int NOT NULL AUTO_INCREMENT, primary key (id)); + CREATE TABLE t2 ( + id int NOT NULL AUTO_INCREMENT, + t1id int NOT NULL, + primary key (id), + CONSTRAINT fk1_en9z857fmvhhyrzb1p7lr751o FOREIGN KEY (t1id) REFERENCES t1 (id) ON DELETE CASCADE + ); + `, + }, + { + schema: ` + CREATE TABLE t1 (id int NOT NULL AUTO_INCREMENT, primary key (id)) CHARSET utf8mb4, COLLATE utf8mb4_unicode_ci; + CREATE TABLE t2 ( + id int NOT NULL AUTO_INCREMENT, + t1id int NOT NULL, + primary key (id), + CONSTRAINT fk1_en9z857fmvhhyrzb1p7lr751o FOREIGN KEY (t1id) REFERENCES t1 (id) ON DELETE CASCADE + ) CHARSET utf8mb4, COLLATE utf8mb4_0900_ai_ci; + `, + }, { schema: "create table t11 (id int primary key, i int, key ix(i), constraint f11 foreign key (i) references t11(id2) on delete restrict)", expectErr: &InvalidReferencedColumnInForeignKeyConstraintError{Table: "t11", Constraint: "f11", ReferencedTable: "t11", ReferencedColumn: "id2"},