question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error when directly setting foreign key and using connect syntax

See original GitHub issue

Bug description

Cannot directly set a foreign key for a relation and use the connect syntax to connect another relation.

First mentioned here: #5788

How to reproduce

Use the client in this way:

await database.user.create({
        data: {
            organisationId: "1234",
            rooms: {
                connect: [{id: "5678"}, {id: "9012"}]
            }
        }
    })

Expected behavior

No Typescript errors

Prisma information

Environment & setup

  • OS: Arch Linux
  • Database: PostgreSQL
  • Node.js version: 17.3.0

Prisma Version

prisma                  : 3.8.0-dev.40
@prisma/client          : 3.8.0-dev.40
Current platform        : debian-openssl-1.1.x
Query Engine (Node-API) : libquery-engine 367f1321e79a7ba33fcac73ed17111312b87e526 (at node_modules/@prisma/engines/libquery_engine-debian-openssl-1.1.x.so.node)
Migration Engine        : migration-engine-cli 367f1321e79a7ba33fcac73ed17111312b87e526 (at node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine    : introspection-core 367f1321e79a7ba33fcac73ed17111312b87e526 (at node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary           : prisma-fmt 367f1321e79a7ba33fcac73ed17111312b87e526 (at node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Default Engines Hash    : 367f1321e79a7ba33fcac73ed17111312b87e526
Studio                  : 0.449.0
Preview Features        : fullTextSearch

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
huzaifahjcommented, Jan 13, 2022
generator client {
    provider        = "prisma-client-js"
    output          = "./generated/client1"
    previewFeatures = ["fullTextSearch"]
}

datasource db {
    provider = "postgresql"
    url      = env("DATABASE_URL")
}

model Organisation {
    id    String @id @default(uuid())
    name  String
    users User[]
    rooms Room[]
}

model User {
    id             String       @id @default(uuid())
    email          String
    rooms          Room[]
    organisation   Organisation @relation(fields: [organisationId], references: [id])
    organisationId String

    @@unique([email, organisationId])
}

model Room {
    id             String       @id @default(uuid())
    name           String
    users          User[]
    organisation   Organisation @relation(fields: [organisationId], references: [id])
    organisationId String
}
1reaction
huzaifahjcommented, Jul 19, 2022

@sourdzl Nope

Read more comments on GitHub >

github_iconTop Results From Across the Web

3 common foreign key mistakes (and how to avoid them)
Dangling foreign keys 3. Not creating foreign key indexes Bonus: Not using foreign keys Key takeaway: think before you CREATE TABLE.
Read more >
MySQL Error Code 1215: "Cannot add foreign key constraint"
How to diagnose: Use SHOW CREATE TABLE parent to check that the local column and the referenced column both have the same data...
Read more >
Syntax error 1064 (42000) when adding foreign key in SQL
First, I added a foreign key to table "Room" so that column roomtype was referencing table Roomtype, column ID. ALTER TABLE room ADD...
Read more >
13.1.17.5 FOREIGN KEY Constraints - MySQL :: Developer Zone
Adding Foreign Key Constraints ... The foreign key can be self referential (referring to the same table). When you add a foreign key...
Read more >
An Essential Guide to MySQL Foreign Key By Practical ...
Finally, specify how foreign key maintains the referential integrity between the child and parent tables by using the ON DELETE and ON UPDATE...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found