Hi, I have a very strange behaviour I don't really understand. When I run a migration adding a colum

Hi, I have a very strange behaviour I don't really understand.
When I run a migration adding a column in Table A (by deferring foreign keys ON, creating a new table, copying all data, deleting the old table, renaming the new table to the name of the old table and setting defer foreign keys OFF), all relations of table B to table A (with the id of A in table B) are now
null
...
How can I work around this? The migration is generated by Prisma and looks like this:
-- RedefineTables
PRAGMA defer_foreign_keys=ON;
CREATE TABLE "new_Product" (
    "id" TEXT NOT NULL PRIMARY KEY,
    "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" DATETIME NOT NULL,
    "name" TEXT NOT NULL,
    "description" TEXT,
    ...some more rows
    CONSTRAINT "Product_eventId_fkey" FOREIGN KEY ("eventId") REFERENCES "Event" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
    CONSTRAINT "Product_totalCapacityId_fkey" FOREIGN KEY ("totalCapacityId") REFERENCES "Capacity" ("id") ON DELETE SET NULL ON UPDATE CASCADE
);
INSERT INTO "new_Product" ("createdAt", "description", "id", "name", "updatedAt", ...) SELECT "createdAt", "description", "id", "name", "updatedAt", ... FROM "Product";
DROP TABLE "Product";
ALTER TABLE "new_Product" RENAME TO "Product";
PRAGMA foreign_key_check("Product");
PRAGMA defer_foreign_keys=OFF;

Any idea? Thanks in advance
Was this page helpful?