https://www.prisma.io/ logo
Join SlackCommunities
Powered by
# orm-help
  • d

    Daniel

    12/05/2021, 3:34 AM
    both items exist in the database in the end
  • j

    John Meyers

    12/05/2021, 7:58 AM
    perhaps because you're awaiting each block inside? I simply put an array of prisma commands inside transaction, see if that would help, e.g
    Copy code
    await prisma.$transaction([
      prisma.item.create({...})
      prisma.item.create({...})
      throw new Error('')
    ])
    It's either that awaits are breaking it, or prisma only breaks the transaction on its own internal database errors, so in that case you wouldn't be able to artificially break it yourself
    d
    • 2
    • 4
  • j

    John Meyers

    12/05/2021, 7:59 AM
    might be wrong here though, not sure!😬
  • b

    Benny

    12/05/2021, 10:18 AM
    Hi, is there an api in Prisma for handling conflicts? Suppose i have a users and posts table and i want to create a post for a user that does not exists. I want after trying to create the post, if im getting Foreign key constraint error i will create the user and then create the post.
    n
    • 2
    • 5
  • b

    Benny

    12/05/2021, 10:18 AM
    (i mean, without raw query)
  • i

    Iddan Aaronsohn

    12/05/2021, 12:24 PM
    Hey, there's something I couldn't understand from the latest release: Are FTS indexes supported in PostgreSQL but only the FTS schema syntax isn't supported for PostgreSQL? If so, why is that?
    j
    j
    • 3
    • 15
  • e

    Eden Lane

    12/05/2021, 3:59 PM
    I have 3 tables. Post, Tag, TagsOnPosts. What is the correct way to update tags on post? Let's say post had 2 tags and I decided to remove 1 tag and 1 more. How to do it in Prisma? Thanks in advance!
    m
    • 2
    • 10
  • p

    Paul

    12/05/2021, 4:42 PM
    Hey all. Has anyone seen this type of error? How do I reset? I'm at 3.6.0 All I did was attempt to remove a column from a table. A push:
    Copy code
    Error: Cannot load from mysql.proc. The table is probably corrupted
       0: migration_core::api::SchemaPush
                 at migration-engine/core/src/api.rs:184
    A migration:
    Copy code
    Error: Cannot load from mysql.proc. The table is probably corrupted
       0: sql_migration_connector::flavour::mysql::sql_schema_from_migration_history
                 at migration-engine/connectors/sql-migration-connector/src/flavour/mysql.rs:424
       1: migration_core::api::DevDiagnostic
                 at migration-engine/core/src/api.rs:108
    j
    • 2
    • 2
  • r

    Ridhwaan Shakeel

    12/05/2021, 6:13 PM
    does anyone know when SQLite will be getting more capabilities and improvements on the prisma client side?
    n
    • 2
    • 1
  • d

    Devi Prasad

    12/06/2021, 1:58 AM
    I get this weird error when I'm trying to insert into a table
    Copy code
    Type: PrismaClientKnownRequestError
    Message: 
    Invalid `prisma.traxRecord.create()` invocation:
    
    
      Null constraint violation on the fields: (`id`)
    
    Code: P2011
    
    Query:
    prisma.traxRecord.create(
    {
      data: {
        back_length: null,
        back_fat: 0,
        frame_score: 0,
        loin_eye_area: 0,
        loin_eye_depth: 0,
        level_1_committed: false,
        level_2_committed: false,
        measured_on: "1970-01-01T00:00:00.000Z",
        birth_weight: 0,
        weaning_weight: 0,
        six_month_weight: 0,
        yearling_weight: 0,
        date_updated: "2021-12-06T01:55:52.424Z",
        type: "SIX_MONTH",
        ipi_definition_id: "",
        goat: {
          connect: {
            id: "c7d04d4d-93e9-43e4-8387-04fb83a3bac8",
          },
        },
        user: {
          connect: {
            id: "9ff02887-f755-49f9-bab2-f8051f66c1b2",
          },
        },
      },
      select: {
        id: true,
        back_length: true,
        back_fat: true,
        frame_score: true,
        loin_eye_area: true,
        loin_eye_depth: true,
        level_1_committed: true,
        level_2_committed: true,
        measured_on: true,
        goat_id: true,
        birth_weight: true,
        weaning_weight: true,
        six_month_weight: true,
        yearling_weight: true,
        user_id: true,
        date_created: true,
        date_updated: true,
        type: true,
        ipi_definition_id: true,
        goat: true,
        user: true,
        six_month_trax_goat: true,
        yearling_trax_goat: true,
      },
    }
    )
    This is my schema, this error is also thrown when using the Prisma Client,
    Copy code
    model TraxRecord {
      id                String         @id @default(uuid())
      back_length       Int?           @db.UnsignedInt
      back_fat          Int            @db.UnsignedInt
      frame_score       Int            @db.UnsignedInt
      loin_eye_area     Int            @db.UnsignedInt
      loin_eye_depth    Int            @db.UnsignedInt
      level_1_committed Boolean
      level_2_committed Boolean
      measured_on       DateTime       @db.Date
      goat_id           String
      birth_weight      Int            @db.UnsignedInt
      weaning_weight    Int            @db.UnsignedInt
      six_month_weight  Int            @db.UnsignedInt
      yearling_weight   Int            @db.UnsignedInt
      user_id           String
      date_created      DateTime       @default(now())
      date_updated      DateTime       @updatedAt
      type              TraxRecordType
      ipi_definition_id String
    
      // ### Relations ### //
      goat                Goat  @relation(fields: [goat_id], references: [id], onUpdate: Restrict)
      user                User  @relation(fields: [user_id], references: [id], onUpdate: Restrict)
      six_month_trax_goat Goat? @relation("six_month_trax", fields: [id], references: [six_month_trax_id], onUpdate: Restrict, map: "six_month_trax_id_t_gt")
      yearling_trax_goat  Goat? @relation("yearling_trax", fields: [id], references: [yearling_trax_id], onUpdate: Restrict, map: "yearling_trax_id_t_gt")
    
      @@index([goat_id], map: "goat_id")
      @@index([user_id], map: "user_id")
      @@map("trax_records")
    }
    
    model Goat {
      id                   String       @id @default(uuid())
      animal_id            String?      @db.VarChar(50)
      name                 String       @db.VarChar(50)
      registration_id      String?      @db.VarChar(50)
      tattoo_le            String?      @db.VarChar(50)
      tattoo_re            String?      @db.VarChar(50)
      date_of_birth        DateTime?    @db.Date
      sex_label            GoatSexLabel
      birth_code           Int          @default(1) @db.UnsignedInt
      breed                String?      @db.VarChar(50)
      sire                 String?      @db.VarChar(50)
      sire_registration_id String?      @db.VarChar(50)
      dam                  String?      @db.VarChar(50)
      dam_registration_id  String?      @db.VarChar(50)
      six_month_trax_id    String?
      yearling_trax_id     String?
      user_id              String
      date_created         DateTime     @default(now())
      date_updated         DateTime     @updatedAt
    
      // ### Relations ### //
      user           User         @relation(fields: [user_id], references: [id], onUpdate: Restrict)
      traxes         TraxRecord[]
      six_month_trax TraxRecord?  @relation("six_month_trax")
      yearling_trax  TraxRecord?  @relation("yearling_trax")
    
      @@index([six_month_trax_id], map: "six_month_trax_id")
      @@index([user_id], map: "user_id")
      @@index([yearling_trax_id], map: "yearling_trax_id")
      @@map("goats")
    }
    a
    • 2
    • 2
  • r

    Ramu Narasinga

    12/06/2021, 5:57 AM
    Hi, this question is related to Prisma Unit Testing: I followed this guide: https://www.prisma.io/docs/guides/testing/unit-testing However, we are getting circular dependancy error, though we added  
    "strictNullChecks": true
     to our 
    tsconfig.json
    . Node Version: 14 "jest-mock-extended": "^2.0.4", For now, we are doing // @ts-ignore to avoid this circular dependancy run-time error. Can any one help how to solve this issue without using ts-ignore?
  • u

    user

    12/06/2021, 11:38 AM
    Tools every developer has in their toolkit (Part 2) #shorts

    https://www.youtube.com/watch?v=mQwIl75JHiwâ–Ÿ

  • u

    user

    12/06/2021, 11:38 AM
    Tools Every Developer has in their Toolkit (Part 1) #shorts

    https://www.youtube.com/watch?v=wr4THNS384Eâ–Ÿ

  • Îł

    ΓÎčÏŽÏÎłÎżÏ‚ ÎšÏÎ±Ï‡Ï„ÏŒÏ€ÎżÏ…Î»ÎżÏ‚

    12/06/2021, 11:44 AM
    Any guide on how to migrate from TypeORM to Prisma. With the OOP architecture that TypeORM uses, I can place reusable functions for a specific model (Entity) and use them anywhere. Is there a way to do something similar in Prisma? Or, do I have to create separate functions that take as a parameter the
    prisma
    client object, and import them every time I want to use them?
    n
    • 2
    • 6
  • p

    Phil Bookst

    12/06/2021, 2:06 PM
    hey is it possible to skip the select when creating a new entry?
    n
    • 2
    • 6
  • b

    beeloon

    12/06/2021, 2:48 PM
    Hi guys! I have a question about relations and deletion: For example, I have 3 tables (Coupon, PromotionOwner, Promotion) Coupon and PromotionOwner implement "one-to-many" relation to Promotion(so one Coupon can have many Promotions, and one PromotionOwner can have many Promotions). I want that behave like this: when I delete PromotionOwner, all Promotions related to it would be deleted, but when I delete a Coupon, all Promotions related to it remain intact. I already had tables for these entities, but now I added such foreign keys: -- AddForeignKey ALTER TABLE "Promotion" ADD FOREIGN KEY ("couponId") REFERENCES "Coupon"("id") ON DELETE NO ACTION ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "Promotion" ADD FOREIGN KEY ("promotionOwnerId") REFERENCES "PromotionOwner"("id") ON DELETE CASCADE ON UPDATE CASCADE; But still receive an Error like on the screenshot, If you know the root of the problem, please help me🙇
  • d

    Daniell

    12/06/2021, 3:41 PM
    In my prisma seed.ts file I have
    import { config } from "./config"
    which causes
    CustomError: Cannot find module '/workspace/prisma/config' imported from /workspace/prisma/seed.ts
    with the following script:
    Copy code
    "seed": "node --experimental-specifier-resolution=node --loader ts-node/esm ./prisma/seed.ts"
  • k

    Kent C. Dodds

    12/06/2021, 4:51 PM
    I noticed there's a
    .prisma/client
    in my
    node_modules
    . Should I be importing types from that instead of
    @prisma/client
    now? It appears that the correct thing to do is import generated types from
    .prisma/client
    and import everything else I need (like
    PrismaClient
    ) from
    @prisma/client
    . Is this correct?
    n
    n
    • 3
    • 3
  • n

    Noel Martin Llevares

    12/06/2021, 5:14 PM
    How do I make this into an error not a warning?
    WARNING The following migrations have been modified since they were applied:
    _20210313140442_favorite_colors_
  • u

    user

    12/06/2021, 5:54 PM
    Migrating a live Prisma project from MySQL to PlanetScale

    https://www.youtube.com/watch?v=JqGrdV5J8KAâ–Ÿ

    In this live stream, Daniel from the Prisma team will be joined by Taylor Barnett from the PlanetScale team to migrate a live Prisma project to PlanetScale from AWS RDS MySQL.
  • c

    Chris Bitoy

    12/06/2021, 8:00 PM
    Happy Monday all, I’m hoping to get help creating an entry in my database using Post request. Below is the issue I am getting as well as steps to recreate. The issue is that the request return an ‘unknown arg’ for fields I defined in my model:
    Copy code
    const creatives = await prisma.creative.create({
             data: {
               brandLogo: 'www.test3.png',
               brandName: 'This another one',
               projectName: 'ProjectName is unique',
               headerImage: 'www.imageheader4.png',
               projectCreative: {
                 cloudinary_url0: '<http://anothertest32.com|anothertest32.com>',
                 ~~~~~~~~~~~~~~~
                 cloudinary_url1: '<http://anothertest33.com|anothertest33.com>',
                 ~~~~~~~~~~~~~~~
                 cloudinary_url2: '<http://anothertest44.com|anothertest44.com>',
                 ~~~~~~~~~~~~~~~
                 cloudinary_url3: '<http://anothertest59.com|anothertest59.com>'
                 ~~~~~~~~~~~~~~~
               }
             }
           })
    
    Unknown arg `cloudinary_url0` in data.projectCreative.cloudinary_url0 for type ProjectCreativeCreateNestedManyWithoutCreativeInput. Did you mean `createMany`? Available args:
    type ProjectCreativeCreateNestedManyWithoutCreativeInput {
      create?: ProjectCreativeCreateWithoutCreativeInput | List<ProjectCreativeCreateWithoutCreativeInput> | ProjectCreativeUncheckedCreateWithoutCreativeInput | List<ProjectCreativeUncheckedCreateWithoutCreativeInput>
      connectOrCreate?: ProjectCreativeCreateOrConnectWithoutCreativeInput | List<ProjectCreativeCreateOrConnectWithoutCreativeInput>
      createMany?: ProjectCreativeCreateManyCreativeInputEnvelope
      connect?: ProjectCreativeWhereUniqueInput | List<ProjectCreativeWhereUniqueInput>
    }
    Unknown arg `cloudinary_url1` in data.projectCreative.cloudinary_url1 for type ProjectCreativeCreateNestedManyWithoutCreativeInput. Did you mean `createMany`? Available args:
    type ProjectCreativeCreateNestedManyWithoutCreativeInput {
      create?: ProjectCreativeCreateWithoutCreativeInput | List<ProjectCreativeCreateWithoutCreativeInput> | ProjectCreativeUncheckedCreateWithoutCreativeInput | List<ProjectCreativeUncheckedCreateWithoutCreativeInput>
      connectOrCreate?: ProjectCreativeCreateOrConnectWithoutCreativeInput | List<ProjectCreativeCreateOrConnectWithoutCreativeInput>
      createMany?: ProjectCreativeCreateManyCreativeInputEnvelope
      connect?: ProjectCreativeWhereUniqueInput | List<ProjectCreativeWhereUniqueInput>
    }
    Unknown arg `cloudinary_url2` in data.projectCreative.cloudinary_url2 for type ProjectCreativeCreateNestedManyWithoutCreativeInput. Did you mean `createMany`? Available args:
    type ProjectCreativeCreateNestedManyWithoutCreativeInput {
      create?: ProjectCreativeCreateWithoutCreativeInput | List<ProjectCreativeCreateWithoutCreativeInput> | ProjectCreativeUncheckedCreateWithoutCreativeInput | List<ProjectCreativeUncheckedCreateWithoutCreativeInput>
      connectOrCreate?: ProjectCreativeCreateOrConnectWithoutCreativeInput | List<ProjectCreativeCreateOrConnectWithoutCreativeInput>
      createMany?: ProjectCreativeCreateManyCreativeInputEnvelope
      connect?: ProjectCreativeWhereUniqueInput | List<ProjectCreativeWhereUniqueInput>
    }
    Unknown arg `cloudinary_url3` in data.projectCreative.cloudinary_url3 for type ProjectCreativeCreateNestedManyWithoutCreativeInput. Did you mean `createMany`? Available args:
    type ProjectCreativeCreateNestedManyWithoutCreativeInput {
      create?: ProjectCreativeCreateWithoutCreativeInput | List<ProjectCreativeCreateWithoutCreativeInput> | ProjectCreativeUncheckedCreateWithoutCreativeInput | List<ProjectCreativeUncheckedCreateWithoutCreativeInput>
      connectOrCreate?: ProjectCreativeCreateOrConnectWithoutCreativeInput | List<ProjectCreativeCreateOrConnectWithoutCreativeInput>
      createMany?: ProjectCreativeCreateManyCreativeInputEnvelope
      connect?: ProjectCreativeWhereUniqueInput | List<ProjectCreativeWhereUniqueInput>
    }
    I defined my models to accept an array of strings as show below:
    Copy code
    model Creative {
      id              Int               @id @default(autoincrement())
      owner_id        String            @default(cuid())
      campaign_id     String            @default(cuid())
      parent_c_id     String            @default(cuid())
      brandLogo       String
      brandName       String            @unique
      projectName     String            @unique
      headerImage     String
      projectCreative ProjectCreative[]  //should accept array of strings
      createdAt       DateTime          @default(now())
      updatedAt       DateTime          @updatedAt
    }
    
    model ProjectCreative {
      id              Int       @id @default(autoincrement())
      creative        Creative? @relation(fields: [creativeId], references: [id])
      creativeId      Int?
      cloudinary_url0 String
      cloudinary_url1 String
      cloudinary_url2 String
      cloudinary_url3 String
      createdAt       DateTime  @default(now())
      updatedAt       DateTime  @updatedAt
    }
    And in my POST route:
    Copy code
    <http://router.post|router.post>("/creatives", async (req, res) => {
      try {
        const { brandLogo, brandName, projectName, headerImage, projectCreative } =
          req.body;
        const creatives = await prisma.creative.create({
          data: { brandLogo, brandName, projectName, headerImage, projectCreative },
        });
        res.status(201).json({ success: true, data: creatives, error: "" });
      } catch (error) {
        console.log(error);
        res.status(500).json({ data: {}, error: error, status: 500 });
      }
    });
    With this test data:
    Copy code
    {
        "brandLogo": "www.test2.png",
        "brandName": "This is a Unique one",
        "projectName": "ProjectName is also unique",
        "headerImage": "www.imageheader.png",
        "projectCreative": {
            "cloudinary_url0": "<http://anothertest32.com|anothertest32.com>",
            "cloudinary_url1": "<http://anothertest33.com|anothertest33.com>",
            "cloudinary_url2": "<http://anothertest44.com|anothertest44.com>",
            "cloudinary_url3": "<http://anothertest59.com|anothertest59.com>"
        }
    Can you help me figure it out?
    m
    • 2
    • 2
  • e

    Eden Lane

    12/06/2021, 9:36 PM
    Hi! I'm trying to apply custom migration with the line
    Copy code
    CREATE ROLE grafana WITH PASSWORD 'password';
    but Prisma falls with the error:
    Copy code
    ERROR: role "grafana" already exists
    I've deleted the role, I've reseted DB but the error is still here. Does anybody know what might be the case?
    • 1
    • 1
  • d

    Daniel Baumert

    12/06/2021, 10:40 PM
    Hello! I am currently testing prisma with nextauth. Currently I have the following problem which already have several: Argument providerAccountId: Got invalid value ‘XXXXXXXXX’ on prisma.findUniqueAccount. Provided String, expected Int. However, in schema.prism I have defined providerAccountId as Int. In the database it is also stored as Int due to the migration. Nevertheless, I get this error. Does anyone know how I can fix this?
    m
    • 2
    • 2
  • j

    Jinho Chung

    12/07/2021, 12:13 AM
    Do you need to perform baselining (
    npx prisma migrate resolve --applied baseline-migration
    ) prior to performing
    npx prisma migrate deploy
    every single time? And if multiple resolves need to be performed, do you just execute them on the CLI or script in succession chronologically until you get to
    migrate deploy
    ?
    ✔ 1
    j
    • 2
    • 2
  • m

    Mike Willbanks

    12/07/2021, 2:18 AM
    Is there eventual plans to support elasticsearch as well as another client?
    n
    • 2
    • 1
  • s

    Stefano Giraldi

    12/07/2021, 9:02 AM
    Hello, I've defined an implicit many-to-many relation between
    User
    and
    Role
    schemas. In my
    seed.ts
    I have this code
    Copy code
    const superadminRole = await prisma.role.upsert({
        where: { name: 'superadmin' },
        update: {},
        create: {
          name: 'superadmin',
        },
      })
    
      const superadmin = await prisma.user.upsert({
        where: { email: '<mailto:superadmin@test.com|superadmin@test.com>' },
        update: {},
        create: {
          email: '<mailto:superadmin@test.com|superadmin@test.com>',
          name: 'Super Admin',
          password: hash,
          roles: {
            connect: [{name: superadminRole.name}] <--- ts2322 error
          }
        },
      })
    I get this typescript error (even if the script works right).
    Copy code
    Type '{ name: string; }' is not assignable to type 'UserRoleWhereUniqueInput'.
      Object literal may only specify known properties, and 'name' does not exist in type 'UserRoleWhereUniqueInput'.ts(2322)
    Can someone help me to understand what is the problem? Thank you
    n
    • 2
    • 6
  • m

    Masayuki Yamaguchi

    12/07/2021, 9:09 AM
    Hi! I’m using “interactiveTransactions”. In following case, both txid1 and txid2 have same value(It means same transaction).
    Copy code
    await prisma.$transaction(async (prisma) => {
        const txid1 = await prisma.$queryRawUnsafe('SELECT txid_current()')
        console.log('txid1', txid1)
    
        const txid2 = await prisma.$queryRawUnsafe('SELECT txid_current()')
        console.log('txid2', txid2)
      })
    But the following case, both txid1 and txid2 have different value(It means different transaction).
    Copy code
    await prisma.$transaction(async (prisma) => {
        const txid1 = await prisma.$queryRawUnsafe('SELECT txid_current()')
        console.log('txid1', txid1)
    
        const txid2 = await prisma.$queryRawUnsafe('SELECT txid_current()').then() // Code changes
        console.log('txid2', txid2)
      })
    I don’t know why the behavior changes. Is this a specification? Is there any way to use “then()” in same transaction? Thank you.
    n
    • 2
    • 4
  • d

    Daniell

    12/07/2021, 9:13 AM
    In my prisma seed.ts file I have
    import { config } from "./config"
    which causes
    CustomError: Cannot find module '/workspace/prisma/config' imported from /workspace/prisma/seed.ts
    with the following script:
    Copy code
    "seed": "node --experimental-specifier-resolution=node --loader ts-node/esm ./prisma/seed.ts"
  • i

    Iradukunda Irenee

    12/07/2021, 9:45 AM
    hello guyz i'm trying to create the tables in your database postgres using heroku by this error any help @nikolasburk, @Julien Goux?
  • i

    Iradukunda Irenee

    12/07/2021, 9:46 AM
    any help because i'm newer in for using prisma as ORM
1...516517518...637Latest