@@ -378,10 +378,31 @@ func TestInvalidSchema(t *testing.T) {
378
378
// InnoDB allows different string length
379
379
schema : "create table t10(id varchar(50) primary key); create table t11 (id int primary key, i varchar(100), key ix(i), constraint f10 foreign key (i) references t10(id) on delete restrict)" ,
380
380
},
381
+ {
382
+ // explicit charset/collation
383
+ schema : "create table t10(id varchar(50) charset utf8mb4 collate utf8mb4_0900_ai_ci primary key); create table t11 (id int primary key, i varchar(100) charset utf8mb4 collate utf8mb4_0900_ai_ci, key ix(i), constraint f10 foreign key (i) references t10(id) on delete restrict)" ,
384
+ },
385
+ {
386
+ // weirdly allowed: varchar->char
387
+ schema : "create table t10(id varchar(50) charset utf8mb4 collate utf8mb4_0900_ai_ci primary key); create table t11 (id int primary key, i char(100) charset utf8mb4 collate utf8mb4_0900_ai_ci, key ix(i), constraint f10 foreign key (i) references t10(id) on delete restrict)" ,
388
+ },
389
+ {
390
+ // but weirdly not allowed: char->varchar
391
+ schema : "create table t10(id char(50) charset utf8mb4 collate utf8mb4_0900_ai_ci primary key); create table t11 (id int primary key, i varchar(50) charset utf8mb4 collate utf8mb4_0900_ai_ci, key ix(i), constraint f10 foreign key (i) references t10(id) on delete restrict)" ,
392
+ expectErr : & ForeignKeyColumnTypeMismatchError {Table : "t11" , Constraint : "f10" , Column : "i" , ReferencedTable : "t10" , ReferencedColumn : "id" },
393
+ },
381
394
{
382
395
schema : "create table t10(id varchar(50) charset utf8mb3 primary key); create table t11 (id int primary key, i varchar(100) charset utf8mb4, key ix(i), constraint f10 foreign key (i) references t10(id) on delete restrict)" ,
383
396
expectErr : & ForeignKeyColumnTypeMismatchError {Table : "t11" , Constraint : "f10" , Column : "i" , ReferencedTable : "t10" , ReferencedColumn : "id" },
384
397
},
398
+ {
399
+ schema : "create table t10(id varchar(50) charset utf8mb4 collate utf8mb4_0900_ai_ci primary key); create table t11 (id int primary key, i varchar(100) charset utf8mb4 collate utf8mb4_general_ci, key ix(i), constraint f10 foreign key (i) references t10(id) on delete restrict)" ,
400
+ expectErr : & ForeignKeyColumnTypeMismatchError {Table : "t11" , Constraint : "f10" , Column : "i" , ReferencedTable : "t10" , ReferencedColumn : "id" },
401
+ },
402
+ {
403
+ schema : "create table t10(id VARCHAR(50) charset utf8mb4 collate utf8mb4_0900_ai_ci primary key); create table t11 (id int primary key, i VARCHAR(100) charset utf8mb4 collate utf8mb4_general_ci, key ix(i), constraint f10 foreign key (i) references t10(id) on delete restrict)" ,
404
+ expectErr : & ForeignKeyColumnTypeMismatchError {Table : "t11" , Constraint : "f10" , Column : "i" , ReferencedTable : "t10" , ReferencedColumn : "id" },
405
+ },
385
406
}
386
407
for _ , ts := range tt {
387
408
t .Run (ts .schema , func (t * testing.T ) {
0 commit comments