on cascade delete issue with multiple foreign keys and migrations

I have a mysql schema like this,
export const table1 = mysqlTable('table1', {
id: int('id').primaryKey().autoincrement()
});

export const table2 = mysqlTable('table2', {
id: int('id').primaryKey().autoincrement(),
fk1: int('fk1')
.references((): AnyMySqlColumn => table1.id)
.notNull(),
fk2: int('fk2')
.references((): AnyMySqlColumn => table1.id)
.notNull()
});
export const table1 = mysqlTable('table1', {
id: int('id').primaryKey().autoincrement()
});

export const table2 = mysqlTable('table2', {
id: int('id').primaryKey().autoincrement(),
fk1: int('fk1')
.references((): AnyMySqlColumn => table1.id)
.notNull(),
fk2: int('fk2')
.references((): AnyMySqlColumn => table1.id)
.notNull()
});
I ran the generate command and then added { onDelete: 'cascade' } to both fk1 and fk2. When i ran generate again, the generated migration file only contains statement for updating cascade delete for fk1.
// 0001_neat_thena.sql
ALTER TABLE `table2` DROP FOREIGN KEY `table2_fk1_table1_id_fk`;
--> statement-breakpoint
ALTER TABLE `table2` ADD CONSTRAINT `table2_fk1_table1_id_fk` FOREIGN KEY (`fk1`) REFERENCES `table1`(`id`) ON DELETE cascade ON UPDATE no action;
// 0001_neat_thena.sql
ALTER TABLE `table2` DROP FOREIGN KEY `table2_fk1_table1_id_fk`;
--> statement-breakpoint
ALTER TABLE `table2` ADD CONSTRAINT `table2_fk1_table1_id_fk` FOREIGN KEY (`fk1`) REFERENCES `table1`(`id`) ON DELETE cascade ON UPDATE no action;
Is this a bug ?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server