Seeding not working in 2.23.0 in Windows
See original GitHub issueBug description
When seeding the database, prisma/seed.ts
doesn’t seem to be getting called, despite saying that it seeded my database. I tried wrapping lines 30-37 in an export const seed = () => { ... };
and also with export default function() { ... }
. In all three cases, none of the console.log()
calls are logged, and the database is not updated. I also know that it knows prisma/seed.ts
exists, as when I delete the file it errors. Reproduction steps are mostly just following the code at Start from scratch | TypeScript & MySQL | Prisma Docs and prisma-examples/seed.ts at latest · prisma/prisma-examples.
(Note: when switching the version of prisma
and @prisma/client
back to 2.22.1
, bug no longer occurs and functionality is normal. Breaks again when switching back to 2.23.0
)
How to reproduce
- Generate a new nodejs project with
yarn init
- Run
yarn add @prisma/client
andyarn add --dev @types/node prisma ts-node typescript
- Run
prisma init
- Set
DATABASE_URL
in.env
file - Create
tsconfig.json
- Run
prisma migrate dev --name init
- Create
seed.ts
in folder withschema.prisma
- Run
prisma db seed --preview-feature
- See output (no console.logs are called, database doesn’t update)
Expected behavior
No response
Prisma information
.env:
DATABASE_URL="mysql://xxx:yyy@zzz/prismabugrepo"
DEBUG="*"
tsconfig.json:
{
"compilerOptions": {
"sourceMap": true,
"outDir": "dist",
"strict": true,
"lib": ["esnext"],
"esModuleInterop": true
}
}
prisma/schema.prisma:
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
model User {
id String @id @default(uuid())
joinedAt DateTime @default(now())
username String @unique
displayName String?
}
prisma/seed.ts:
import {Prisma, PrismaClient} from "@prisma/client";
console.log("Top of script");
const prisma = new PrismaClient({
log: ["query", "info", "warn", "error"]
});
const main = async () => {
console.log("Start seeding...");
const userData: Prisma.UserCreateInput[] = [
{
username: "user123",
displayName: "User One Two Three"
}
];
for (const u of userData) {
const user = await prisma.user.create({
data: u
});
console.log(`Created user with ID ${user.id}`);
}
console.log("Finished seeding.");
};
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});
console.log("Bottom of script");
Console Output:
C:\Programming\prisma-bug-repro> prisma db seed --preview-feature
Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
Running seed from prisma\seed.ts ...
Your database has been seeded.
C:\Programming\prisma-bug-repro>
Environment & setup
- OS: Windows 10 Version 20H2 (OS build 19042.985)
- Database: MySQL
- Node.js version: 16.0.0
Prisma Version
prisma : 2.23.0
@prisma/client : 2.23.0
Current platform : windows
Query Engine : query-engine adf5e8cba3daf12d456d911d72b6e9418681b28b (at node_modules\@prisma\engines\query-engine-windows.exe)
Migration Engine : migration-engine-cli adf5e8cba3daf12d456d911d72b6e9418681b28b (at node_modules\@prisma\engines\migration-engine-wi
ndows.exe)
Introspection Engine : introspection-core adf5e8cba3daf12d456d911d72b6e9418681b28b (at node_modules\@prisma\engines\introspection-engine-
windows.exe)
Format Binary : prisma-fmt adf5e8cba3daf12d456d911d72b6e9418681b28b (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash : adf5e8cba3daf12d456d911d72b6e9418681b28b
Studio : 0.393.0
Issue Analytics
- State:
- Created 2 years ago
- Reactions:30
- Comments:17 (6 by maintainers)
Top GitHub Comments
I can confirm this regression. We will fix this.
Same issue too with 2.26