Hello, connect fails silently. I only discovered ...
# orm-help
k
Hello, connect fails silently. I only discovered the issue after running the logged insert statement to mysql workbench. This is the error I get: `1452 Cannot add or update a child row: a foreign key constraint fails (
DB
.
_FavoriteItems
, CONSTRAINT
_FavoriteItems_ibfk_1
FOREIGN KEY (
A
) REFERENCES
Item
(
id
) ON DELETE CASCADE ON UPDATE CASCADE)` this is the mysql table:
Copy code
'CREATE TABLE `_FavoriteItems` (
  `A` char(25) CHARACTER SET utf8 NOT NULL,
  `B` char(25) CHARACTER SET utf8 NOT NULL,
  UNIQUE KEY `_FavoriteItems_AB_unique` (`A`,`B`),
  KEY `_FavoriteItems_B_index` (`B`),
  CONSTRAINT `_FavoriteItems_ibfk_1` FOREIGN KEY (`A`) REFERENCES `Item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `_FavoriteItems_ibfk_2` FOREIGN KEY (`B`) REFERENCES `User` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci'
this is the prisma model:
Copy code
model Item {
  favoritedBy       User[]        @relation("FavoriteItems")
}

model User {
  favoriteItems      Item[]        @relation("FavoriteItems")
}
and this is the insert/connect statement:
Copy code
INSERT IGNORE INTO 
	`DB`.`_FavoriteAds` (
		`DB`.`_FavoriteItems`.`A`,
        `DB`.`_FavoriteItems`.`B`
	 ) VALUES ("itemId","userId")
Note that both itemId and userId exist in the database. A user can have many favorite items.
j
So you should be able to run the query manually, but are also not?
k
It fails silently on Prisma's side, and errs on mysql workbench side.
I figured it out the by the way.
The upgrade cli missed updating join-table id fields (A and B) length from 25 to 30. Child tables were changed to 30, but the _FavoriteItems column weren't. So that is the issue, and the solution.