Hi I'm new to prisma and i'm blocking on seeding m...
# orm-help
b
Hi I'm new to prisma and i'm blocking on seeding my database. Injecting simple data works perfectly but when model became more complicated with foreign keys, Prisma does not agree How do you seed your db with auto incremented foreign keys ?, and same question with many-to-many releation ?
👀 1
My model looks like that :
Copy code
model Organization {
  id              String @id @db.Uuid @default(uuid())
  name            String
  email           String @unique
  teams           Team[]
}

model Team {
  id              String @id @db.Uuid @default(uuid()) @unique
  name            String
  avatar          Bytes?
  Organization    Organization @relation(fields: [organizationId], references: [id])
  organizationId  String @db.Uuid
  users           UserInTeams[]
}

model User {
  id              String @id @db.Uuid @default(uuid()) @unique
  firstname       String
  lastname        String
  email           String @unique
  teams           UserInTeams[]
  organizations   UserInOrganization[]
}
To add organizations i have to create some Team
Copy code
const organizations = [
    {
        name: "Google",
        email: "<mailto:contact@google.com|contact@google.com>",
        teams :{
            create: [
                { name: "Best team" },
                { name: "Rockstar" },
            ]
        },
    }
]

async function main() {
    await prisma.organization.createMany({ data: organizations })
}
prisma throw `Unknown arg
teams
in data.0.teams for type OrganizationCreateManyInput. Did you mean
name
? Available args:` So i can't create multiple organization at once.
a
Hey Benjamin! It is not yet possible in Prisma to do nested writes during a bulk operation like
createMany
. We have an outstanding feature request for it, so feel free to add a +1 and your specific use case, if it hasn’t been covered already. This helps our engineering teams prioritize for the future!
b
Hi Austin, Thanks for your response. It is more a lack of knowledge than a lack in the framework 🙂 The solution is to add objects one by one and use them in other query