title: How can I use createMany with foreign keys in prisma?
body: <p>I am a beginner in using Prisma and am stuck at trying to figure out how to initially load data into postgres tables. I have tried seeding my db as per this example in prisma
  <a href="https://github.com/prisma/prisma-examples/tree/latest/javascript/graphql-auth" rel="nofollow noreferrer">https://github.com/prisma/prisma-examples/tree/latest/javascript/graphql-auth</a>
  but it seems the main() is not getting triggered by the command &quot;npx prisma db seed --preview-feature&quot;.
  So I tried to insert into my db through a temporary function but I am getting an invalid invocation error on starting dev server:</p>
  <p><code>Foreign key constraint failed on the field: Animals_categoryName_fkey (index)</code></p>
  <p>But I am not getting this error when I don't use foreign keys. Below is my schema.prisma, types and the data that I need to add.</p>
  <p>Schema.prisma</p>
  <pre><code>datasource db {
    provider = &quot;postgresql&quot;
    url      = env(&quot;DATABASE_URL&quot;)
  }
  
  generator client {
    provider = &quot;prisma-client-js&quot;
  }
  
  model Animals{
    id Int @id @default(autoincrement())
    image String
    price String
    description String[]
    stock Int
    onSale Boolean
    title String
    category Category @relation(fields: [categoryName], references: [categoryName])
    slug String @unique
    categoryName String
  }
  
  model Category{
    id Int @id @default(autoincrement())
    image String
    categoryName String @unique
    animals Animals[]
  }
  
  model MainCards{
    cardId Int @id @default(autoincrement())
    image String
    title String
  }
  </code></pre>
  <p>typedefs--</p>
  <pre><code>const typeDefs = gql`
        type MainCard {
            title: String!
            image: String!
        }
      
        type Animals{
          id: ID!
          image: String!
          price: String!
          description: [String!]!
          stock: Int!
          onSale: Boolean
          slug: String
          categoryName: String
          title: String
        }
      
        type Category{
          id: ID!
          image: String!
          categoryName: String!
        }
      
        type Query {
          mainCards: [MainCard]
          animals: [Animals]
          animal(slug: String!): Animals
          categories: [Category]
          category(categoryName: String!): [Animals]
        }
      `;
  </code></pre>
  <p>Part of data to add:</p>
  <pre><code>const AnimalsData = async () =&gt; {
      await prisma.animals.createMany({
          data: [
              {
                  image: &quot;lion&quot;,
                  title: &quot;7-year Male Lion with Large Well Kept Main with a Beautiful Yellow/Brownish Color&quot;,
                  price: &quot;23,322&quot;,
                  description: [
                      &quot;Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.&quot;,
                      &quot;Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.&quot;,
                      &quot;Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.&quot;,
                      &quot;Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.&quot;
                  ],
                  stock: 14,
                  onSale: false,
                  slug: &quot;lion&quot;,
                  categoryName: &quot;cats&quot;
              },            
              {
                  image: &quot;gorilla&quot;,
                  title: &quot;Black Haired Gorilla with Broad Chest and Shoulder. Would be an Excellent Spot at the Gym&quot;,
                  price: &quot;47,775&quot;,
                  description: [
                      &quot;Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.&quot;,
                      &quot;Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.&quot;,
                      &quot;Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.&quot;,
                      &quot;Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.&quot;
                  ],
                  stock: 14,
                  onSale: false,
                  slug: &quot;gorilla&quot;,
                  categoryName: &quot;mammals&quot;
              }            
          ]
      })
  }
  
  AnimalsData()
  .catch(e =&gt; {throw e})
  .finally(async () =&gt; {await prisma.$disconnect()})
  </code></pre>
  <p>If it helps in any way, I am using prisma 2.24, apollo and graphql with a postgres database.
  Any help or suggestion is greatly appreciated.</p>