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

    khareta

    06/22/2021, 2:59 PM
    Hello, connect fails silently. I only discovered the issue after running the logged insert statement to mysql workbench. This is the error I get: `1452 Cannot add or update a child row: a foreign key constraint fails (
    DB
    .
    _FavoriteItems
    , CONSTRAINT
    _FavoriteItems_ibfk_1
    FOREIGN KEY (
    A
    ) REFERENCES
    Item
    (
    id
    ) ON DELETE CASCADE ON UPDATE CASCADE)` this is the mysql table:
    Copy code
    'CREATE TABLE `_FavoriteItems` (
      `A` char(25) CHARACTER SET utf8 NOT NULL,
      `B` char(25) CHARACTER SET utf8 NOT NULL,
      UNIQUE KEY `_FavoriteItems_AB_unique` (`A`,`B`),
      KEY `_FavoriteItems_B_index` (`B`),
      CONSTRAINT `_FavoriteItems_ibfk_1` FOREIGN KEY (`A`) REFERENCES `Item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
      CONSTRAINT `_FavoriteItems_ibfk_2` FOREIGN KEY (`B`) REFERENCES `User` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci'
    this is the prisma model:
    Copy code
    model Item {
      favoritedBy       User[]        @relation("FavoriteItems")
    }
    
    model User {
      favoriteItems      Item[]        @relation("FavoriteItems")
    }
    and this is the insert/connect statement:
    Copy code
    INSERT IGNORE INTO 
    	`DB`.`_FavoriteAds` (
    		`DB`.`_FavoriteItems`.`A`,
            `DB`.`_FavoriteItems`.`B`
    	 ) VALUES ("itemId","userId")
    Note that both itemId and userId exist in the database. A user can have many favorite items.
    j
    • 2
    • 4
  • k

    khareta

    06/22/2021, 3:00 PM
    How can I fix that issue on mysql level at least?
  • c

    Copium Dealer

    06/22/2021, 5:02 PM
    Hey, any suggestions on what platform to deploy a PSQL DB?
  • c

    Copium Dealer

    06/22/2021, 5:02 PM
    For use with Vercel. DB may become quite large, would like it to not be too pricey
    s
    l
    • 3
    • 2
  • a

    Arun Kumar

    06/22/2021, 5:37 PM
    Should we run the introspect and generate command on the docker as well. Or is it enough to run it on the local machine?
  • a

    Arun Kumar

    06/22/2021, 5:49 PM
    I'm already using the
    --force
    command but still the docker says that schema is invalid and I should run with the
    --force
    flag.
    Copy code
    Step 8/10 : RUN npx prisma introspect --force
     ---> Running in ff2f1297b22c
    Prisma schema loaded from prisma/schema.prisma
    
    Introspecting based on datasource defined in prisma/schema.prisma …
    
    Error: P1012 Introspection failed as your current Prisma schema file is invalid
    
    Please fix your current schema manually, use prisma validate to confirm it is valid and then run this command again.
    Or run this command with the --force flag to ignore your current schema and overwrite it. All local modifications will be lost.
    
    npm notice 
    npm notice New minor version of npm available! 7.15.1 -> 7.18.1
    npm notice Changelog: <<https://github.com/npm/cli/releases/tag/v7.18.1>>
    npm notice Run `npm install -g npm@7.18.1` to update!
    npm notice 
    The command '/bin/sh -c npx prisma introspect --force' returned a non-zero code: 1
    
    Error: Process completed with exit code 1.
    j
    • 2
    • 8
  • a

    ali

    06/23/2021, 6:04 AM
    Hi I am expecting a transaction to fail due to uniqueness violation, but on failure error raised is of type `Error`and not
    PrismaClientKnownRequestError
    as documented here: https://www.prisma.io/docs/reference/api-reference/error-reference Is my understanding incorrect? Please let me know. Thanks.
    r
    • 2
    • 2
  • m

    Marko

    06/23/2021, 8:22 AM
    Hello! I am currently having some weird issues with timezones. Just for testing I created the following columns (using Postgres):
    Copy code
    testAt   DateTime
    testTzAt DateTime @db.Timestamptz
    From my understanding timestamp without timezone should store DateTime in the local time, but for what ever reason, when ever I save this, both of them get converted to UTC:
    Copy code
    testAt: '2021-06-24T01:16:14.963+02:00',
    testTzAt: '2021-06-24T01:16:14.963+02:00',
    When I read the selected row, this is what I get back:
    Copy code
    testAt: 2021-06-23T23:16:14.963Z,
    testTzAt: 2021-06-23T23:16:14.963Z,
    What am I doing wrong here, because currently I don't see any difference here. Thank you!
    o
    • 2
    • 3
  • o

    Orkhan Rustamli

    06/23/2021, 8:27 AM
    Is there any way to use GraphQL Fragments with Prisma 2. I do not like to use "include" options as nested queries with separate query definition provide you as much depth as you want. I saw in some tutorials to use Fragments with Prisma 1 (graphql-bindings) but not sure about Prisma 2.
    r
    • 2
    • 1
  • s

    Subash Ganesh

    06/23/2021, 9:31 AM
    Hi Guys. I need to Save Latitude Longitude value in postgres. How can I achieve this in prisma. and I need to find the closest points of given lat long Value. Thanks in advance.
    ✅ 1
    👀 3
    d
    r
    • 3
    • 3
  • n

    Nichita Z

    06/23/2021, 9:54 AM
    Hi all! I have a problem with queryRaw: I’m trying to run a query that returns multiple columns with the same name (it’s a join between multiple tables). Unfortunately, when prisma converts it to a JS object, the object only contains the last column. So if I have 2 createdAt columns, the first one has a value and the second one has NULL, it will return createdAt: NULL. Is there any kind of easy fix for this?
    r
    r
    • 3
    • 3
  • h

    Halvor

    06/23/2021, 12:21 PM
    how can i add 2 new json fields to an already existing json to send with data: {} in a query?
    r
    • 2
    • 5
  • d

    Dan Shapir

    06/23/2021, 12:27 PM
    createMany has really really bad performance, almost 20 seconds to insert 100 rows… With around 10 columns each, mainly numbers. I’ve tested the query and it creates one big insert, with multiple variables, but it super slow.
    j
    • 2
    • 2
  • n

    Nikhil Goyal

    06/23/2021, 12:30 PM
    How can I check whether my prisma connection is up and running or not via code? I need to implement a database health service API in prisma.
    j
    r
    • 3
    • 11
  • l

    Leandro F.Laurito

    06/23/2021, 12:42 PM
    Hello guys im new here, I've been working with Prisma recently and im really curious to know if theres a way to serialize prisma objects using "class-transform" npm package. If is not possible do you guys have any recommendation on how to do it?
  • f

    Felipe Belinassi

    06/23/2021, 12:45 PM
    Hi guys! I have some database tables which has a non-incremental id field (Int). For every new entry I need to manually increase this value, and I can't change the database model because these are legacy tables with huge amount of data. I did some research but didn't find any relevant examples. I was thinking of doing something like this:
    Copy code
    const data = await prisma.model.create({
      data: {
        id: (await prisma.model.count()) + 1,
        ...params,
      },
    });
    Is there other way for doing this?
    n
    r
    • 3
    • 8
  • h

    Halvor

    06/23/2021, 1:37 PM
    Can i do something similar to "SUM(field) AS field" with prisma aggregate functions?
  • h

    Halvor

    06/23/2021, 1:37 PM
    I need to summerize every field in a table.
    r
    • 2
    • 6
  • m

    manuel

    06/23/2021, 2:18 PM
    Is there a general guide how to deal with deployment environments regarding prisma and the db and vercel?
    j
    • 2
    • 2
  • u

    user

    06/23/2021, 3:16 PM
    Eine praktische Einführung in Prisma [Einladung]: Carmen Berndt

    https://www.youtube.com/watch?v=bOOGWn1hQMQ▾

    In diesem anfängerfreundlichen und praktischen Workshop wirst du die Grundlagen lernen um das Prisma ORM mit TypeScript zu verwenden. Der Workshop hat die folgenden Inhalte: ✅ Prisma mit einer SQLite Datenbank aufsetzen ✅ Datenmodellierung, Migrationen & Datenbankabfragen ✅ API Entwicklung mit REST & GraphQL Voraussetzungen: • Node.js: 12.2.X / 14.X • Du benötigst KEINE Vorkenntnisse in TypeScript und SQL um am Workshop teilzunehmen Der Workshop ist für etwa 150min geplant. https://www.prisma.io​​​/day Learn more about Prisma: ◭ Website: https://www.prisma.io​​​ ◭ Docs: https://www.prisma.io/docs​​​ ◭ Quickstart: https://www.prisma.io/docs/getting-started/quickstart-typescript
    germany parrot 3
  • f

    Faiyam Rahman

    06/23/2021, 9:22 PM
    Hey all! Does anyone know of a good link from which to understand the new
    UncheckedInput
    types in prisma two? I searched
    unchecked
    and
    unchecked input
    on the prisma docs and couldn't find any. For context, I'm running into an error on a nested write where I expect to be able to define writes on a connected relation, but for some reason prisma is using the "unchecked" input, which doesn't allow writes on the connected relation.
    r
    • 2
    • 2
  • h

    Halvor

    06/23/2021, 10:34 PM
    How can i with an aggregate function make it summarize values and count NULL as zero?
  • h

    Halvor

    06/23/2021, 10:35 PM
    That is it no rows returned in query exists.
  • h

    Halvor

    06/23/2021, 10:46 PM
    Was this not fixed in https://github.com/prisma/prisma-engines/pull/1092?
    r
    • 2
    • 5
  • n

    nikunj chaudhari

    06/24/2021, 3:02 AM
    i have graphql resolver in different file. In resolver's context i have prisma. something like this
    Copy code
    new ApolloServer({ schema, context: { prisma } });
    since i am using ts but i couldn't get autocomplete or suggestion.
    r
    • 2
    • 4
  • c

    Copium Dealer

    06/24/2021, 3:05 AM
    Is it possible to set up PSQL triggers in Prisma? I have an entity (lets say Posts). Posts can have many Likes. If a Post receives 500 likes, the "popular" boolean should be set to true. I also want it to increment a "likeCount" integer on that Post too.
    r
    • 2
    • 1
  • c

    Copium Dealer

    06/24/2021, 3:05 AM
    I'm struggling to see if this is possible
  • c

    Copium Dealer

    06/24/2021, 3:07 AM
    Right now I have a cron job that executes every minute or so for every Post that exists...as you can imagine this is not ideal
  • a

    Arun Kumar

    06/24/2021, 8:15 AM
    Is it possible to make the create method ignore the values that are not there in the schema.
    m
    • 2
    • 4
  • h

    Henri Kuper

    06/24/2021, 9:23 AM
    I start using the prisma studio desktop app (for mac): in my schema I have set the url to
    url = env("POSTGRES_URL")
    to work with local, dev and prod environments without manually set the url into the schema. The app says
    error: Environment variable not found: POSTGRES_URL.
    It works fine if I open prisma studio from the terminal. Is there I way to add e.g 3 urls that I can select, to quickly work with the app on local, dev and prod? Do I miss anything? Otherwise I would need to add the full url directly to the schema each time, which is not very handy.
    r
    • 2
    • 17
1...448449450...637Latest