Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when using "multiSchema" with custom database schema and implicit Many To Many relation #16761

Closed
leidison opened this issue Dec 13, 2022 · 0 comments · Fixed by prisma/prisma-engines#3523
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. tech/engines Issue for tech Engines. topic: implicit m:n implicit many-to-many relations topic: m:n many-to-many relations topic: multiSchema multiple schemas
Milestone

Comments

@leidison
Copy link

leidison commented Dec 13, 2022

Bug description

I coded a ManyToMany relationship between Organization and Repository entities, with the custom schema called "organization". However, when trying to connect a Repository in Organization, the following error occurs:

[Nest] 2119  - 12/13/2022, 12:14:13 AM   ERROR [ExceptionsHandler] 
Invalid `prisma.organization.create()` invocation in
/workspace/app/src/services/organization/organization.service.ts:31:50

  28   },
  29 });
  30 
  31 const organization = await prisma.organization.create(
The table `public._OrganizationToRepository` does not exist in the current database.
Error: 
Invalid `prisma.organization.create()` invocation in
/workspace/app/src/services/organization/organization.service.ts:31:50

  28   },
  29 });
  30 
  31 const organization = await prisma.organization.create(
The table `public._OrganizationToRepository` does not exist in the current database.
    at RequestHandler.handleRequestError (/workspace/app/node_modules/@prisma/client/runtime/index.js:34869:13)
    at RequestHandler.handleAndLogRequestError (/workspace/app/node_modules/@prisma/client/runtime/index.js:34841:12)
    at RequestHandler.request (/workspace/app/node_modules/@prisma/client/runtime/index.js:34836:12)
    at PrismaService._request (/workspace/app/node_modules/@prisma/client/runtime/index.js:35926:16)
    at /workspace/app/src/services/organization/organization.service.ts:31:28
    at Proxy._transactionWithCallback (/workspace/app/node_modules/@prisma/client/runtime/index.js:35858:18)
    at OrganizationService.create (/workspace/app/src/services/organization/organization.service.ts:16:12)
    at /workspace/app/node_modules/@nestjs/core/router/router-execution-context.js:46:28
    at Object.<anonymous> (/workspace/app/node_modules/@nestjs/core/router/router-proxy.js:9:17)

How to reproduce

  1. Go to prisma schema
  2. Create ManyToMany relation, with @@Schema("organization")
  3. Create a object with prisma create method
  4. Create another object with prisma create method, using connect to bind object created on step 3
  5. Run your application
  6. See error

The table public._OrganizationToRepository does not exist in the current database.

Expected behavior

The correct thing would be to use the "organization" schema. But, the "public" schema was used.

Prisma information

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["multiSchema"]
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
  schemas  = ["organization", "security"]
}

model Organization {
  id           String       @id @default(uuid())
  name     String
  //
  repositories Repository[]
  //

  @@schema("organization")
}

model Repository {
  id            BigInt         @id @default(autoincrement())
  name      String
  //
  organizations Organization[]

  @@schema("organization")
}
const repository = await prisma.repository.create({
  data: {
    name: 'Repository 1',
  },
});

const organization = await em.organization.create({
  data: {
    name: 'Organization 1',
    repositories: {
      // exception throw here
      connect: {
        id: repository.id,
      },
    },
  },
});

Environment & setup

  • OS: Ubuntu 20.04
  • Database: PostgreSQL
  • Node.js version: v18.12.1

Prisma Version

prisma                  : 4.7.1
@prisma/client          : 4.7.1
Current platform        : debian-openssl-1.1.x
Query Engine (Node-API) : libquery-engine 272861e07ab64f234d3ffc4094e32bd61775599c (at node_modules/@prisma/engines/libquery_engine-debian-openssl-1.1.x.so.node)
Migration Engine        : migration-engine-cli 272861e07ab64f234d3ffc4094e32bd61775599c (at node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine    : introspection-core 272861e07ab64f234d3ffc4094e32bd61775599c (at node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary           : prisma-fmt 272861e07ab64f234d3ffc4094e32bd61775599c (at node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Format Wasm             : @prisma/prisma-fmt-wasm 4.7.1-1.272861e07ab64f234d3ffc4094e32bd61775599c
Default Engines Hash    : 272861e07ab64f234d3ffc4094e32bd61775599c
Studio                  : 0.477.0
Preview Features        : multiSchema
@leidison leidison added the kind/bug A reported bug. label Dec 13, 2022
@leidison leidison changed the title Error when using "multiSchema" with custom database schema Error when using "multiSchema" with custom database schema and ManyToMany relation Dec 13, 2022
@leidison leidison changed the title Error when using "multiSchema" with custom database schema and ManyToMany relation Error when using "multiSchema" with custom database schema and Many To Many relation Dec 13, 2022
@Druue Druue added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. tech/engines Issue for tech Engines. team/schema Issue for team Schema. topic: multiSchema multiple schemas team/client Issue for team Client. and removed team/schema Issue for team Schema. labels Dec 13, 2022
@janpio janpio added topic: m:n many-to-many relations topic: implicit m:n implicit many-to-many relations labels Dec 13, 2022
@janpio janpio changed the title Error when using "multiSchema" with custom database schema and Many To Many relation Error when using "multiSchema" with custom database schema and implicit Many To Many relation Dec 13, 2022
tomhoule added a commit to prisma/prisma-engines that referenced this issue Dec 16, 2022
We did not add any schema prefix there.

We now add the correct one (the schema of the first model).

closes prisma/prisma#16761
tomhoule added a commit to prisma/prisma-engines that referenced this issue Dec 16, 2022
We did not add any schema prefix there.

We now add the correct one (the schema of the first model).

closes prisma/prisma#16761
@janpio janpio added this to the 4.8.0 milestone Dec 16, 2022
@janpio janpio added bug/2-confirmed Bug has been reproduced and confirmed. and removed bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Dec 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. tech/engines Issue for tech Engines. topic: implicit m:n implicit many-to-many relations topic: m:n many-to-many relations topic: multiSchema multiple schemas
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants