P
Prisma•4d ago
Lambertn33

adapter

Good day everyone, I am using nest.js with prisma in a docker environment but I haven't succeeded to seed my Database due to the following error in the attached inage. could some give some help?
No description
14 Replies
Prisma AI Help
Prisma AI Help•4d ago
You selected the carefully hand-crafted route. A dev artisan will respond soon. Meanwhile, the #ask-ai channel awaits if you're curious!
Nurul
Nurul•4d ago
Hi @Lambertn33! Are you using Accelerate connection string? Starting with (prisma+postgres://) or are using a normal TCP connection string (starting with postgres:// or postgresql://)? Could you share how you are instantiating Prisma Client?
Lambertn33
Lambertn33OP•4d ago
Hello @Nurul (Prisma) Thank you for your reply, I am using mysql/mariaDB adapter. here is my prisma.config.ts: import 'dotenv/config'; import { defineConfig, env } from 'prisma/config'; export default defineConfig({ schema: 'prisma/schema.prisma', migrations: { path: 'prisma/migrations', seed: 'tsx prisma/seed.ts', }, datasource: { url: env('DATABASE_URL'), }, }); and my prisma file: import { PrismaClient } from '@prisma/client'; import 'dotenv/config'; import { PrismaMariaDb } from '@prisma/adapter-mariadb'; const adapter = new PrismaMariaDb({ host: process.env.DB_HOST 'db', port: parseInt(process.env.DB_PORT '3306', 10), user: process.env.DB_USERNAME 'taskbid', password: process.env.DB_PASSWORD 'taskbid', database: process.env.DB_NAME || 'taskbid', connectionLimit: 10, }); const prisma = new PrismaClient({ adapter }); export default prisma; and my schema.prisma: generator client { provider = "prisma-client-js" } datasource db { provider = "mysql" } model User { id String @id @default(uuid()) names String email String @unique password String role Role @default(FREELANCER) lastLogin DateTime? createdAt DateTime @default(now()) updatedAt DateTime @updatedAt freelancer Freelancer? @@map("users") } is there something that I am missing/doing wrong please?
Nurul
Nurul•4d ago
I assume your MariaDB instance is running via docker? Are you able to connect to it via an Database IDE?
Lambertn33
Lambertn33OP•4d ago
Yes I am using docker, I have been able to access my DB using the docker exec command.
Nurul
Nurul•4d ago
With Prisma 7 it is recommended to use the prisma-client generator:
generator client {
provider = "prisma-client"
}
generator client {
provider = "prisma-client"
}
but that should not cause this issue.
Lambertn33
Lambertn33OP•4d ago
@Nurul i updated as shown in the attached image, but also I got the diffrerent error
No description
Nurul
Nurul•4d ago
Did you run npx prisma generate after changing generator to prisma-client?
Lambertn33
Lambertn33OP•4d ago
Yes I did
Nurul
Nurul•4d ago
Also your import seems to be wrong. You are importing it like this: import { PrismaClient } from '@prisma/client'; It should instead be from the output path you have generated. import { PrismaClient } from '../generated/prisma/client'
Lambertn33
Lambertn33OP•4d ago
@Nurul after updating all these I came back to the initial problem of Database connectivity, the migration works but the seed keeps failing.. here is the seeding codes: import bcrypt from 'bcryptjs'; import prisma from './prisma'; async function main() { const password = await bcrypt.hash('password123', 10); // Create Admin User const adminUser = await prisma.user.create({ data: { names: 'TaskBid Admin', email: 'admin@taskbid.com', password, role: 'ADMIN', }, include: { freelancer: true, }, }); // Create Freelancer User const freelancerUser = await prisma.user.create({ data: { names: 'Demo Freelancer', email: 'freelancer@taskbid.com', password, role: 'FREELANCER', }, include: { freelancer: true, }, }); console.log('Seeded data:', { admin: adminUser.email, freelancer: freelancerUser.email, }); } main() .catch((e) => { console.error(e); process.exit(1); }) .finally(async () => { await prisma.$disconnect(); });
No description
Nurul
Nurul•4d ago
Do you get the same error if you try to initialise Prisma Client like this:
const adapter = new PrismaMariaDb(env.DATABASE_URL);
const prisma = new PrismaClient({ adapter });
const adapter = new PrismaMariaDb(env.DATABASE_URL);
const prisma = new PrismaClient({ adapter });
Just pass the entire connection string via DATABASE_URL and check? The issue is with connecting to the database for some reason
Lambertn33
Lambertn33OP•4d ago
@Nurul it seems to work now. I needed to review and make sure the docker-compose yml credentials mtach with the ,env credentials.. God bless you for your help..
Nurul
Nurul•4d ago
I am glad to hear that the issue is resolved 🎉

Did you find this page helpful?