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

@map field name swap causes "Field is already defined on model" error #8687

Closed
garth opened this issue Aug 11, 2021 · 3 comments
Closed

@map field name swap causes "Field is already defined on model" error #8687

garth opened this issue Aug 11, 2021 · 3 comments
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. domain/schema Issue in the "Schema" domain: Prisma Schema, Introspection, Migrations etc. kind/bug A reported bug. topic: validation
Milestone

Comments

@garth
Copy link

garth commented Aug 11, 2021

Bug description

When using @Map to rename fields, you get the following error when the model has a name that is mapped to a table that has a different field of the same name.

Field "name" is already defined on model "Thing".

How to reproduce

model Thing {
  name         String  @map("new_name")
  old_name  String  @map("name")
}

Expected behavior

There should be no error

Prisma information

model Thing {
  name         String  @map("new_name")
  old_name  String  @map("name")
}

Environment & setup

  • OS: Mac OS
  • Database: PostgreSQL
  • Node.js version: v16.6.1

Prisma Version

prisma               : 2.29.0
@prisma/client       : 2.29.0
Current platform     : darwin
Query Engine         : query-engine 1be4cd60b89afa04b192acb1ef47758a39810f3a (at node_modules/@prisma/engines/query-engine-darwin)
Migration Engine     : migration-engine-cli 1be4cd60b89afa04b192acb1ef47758a39810f3a (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core 1be4cd60b89afa04b192acb1ef47758a39810f3a (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary        : prisma-fmt 1be4cd60b89afa04b192acb1ef47758a39810f3a (at node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash : 1be4cd60b89afa04b192acb1ef47758a39810f3a
Studio               : 0.419.0
@garth garth added the kind/bug A reported bug. label Aug 11, 2021
@janpio janpio added bug/2-confirmed Bug has been reproduced and confirmed. domain/schema Issue in the "Schema" domain: Prisma Schema, Introspection, Migrations etc. topic: validation labels Aug 12, 2021
@janpio
Copy link
Contributor

janpio commented Aug 12, 2021

I can confirm something going wrong here, weirdly my error message is different though:

model Thing {
  id       Int    @id @default(autoincrement())
  name     String @map("new_name")
  old_name String @map("name")
}

image

Note how it says"Field "old_name" is already defined on model "Thing".

Was that just a typo above @garth or do you indeed get a message about the field name?

@garth
Copy link
Author

garth commented Aug 12, 2021

Sorry, I just typed out the schema roughly like I have in my project and renamed the fields, so probably got the fields the wrong way around. Glad that you could reproduce. Actually the bug has been there for quite some time, but I think 2.7 started failing the builds due to lint errors, before it was just an erroneous error in vs code that could be safely ignored.

@Jolg42 Jolg42 added this to the 3.7.0 milestone Dec 1, 2021
@Jolg42 Jolg42 modified the milestones: 3.7.0, 3.8.0 Dec 21, 2021
@pimeys pimeys self-assigned this Jan 5, 2022
@pimeys
Copy link
Contributor

pimeys commented Jan 5, 2022

I remember I fixed this already and that is a perfect excuse to do some git bisect. Our main branch allows your example, 2.29.0 does not. Bisect tells me I sure did fix it in prisma/prisma-engines#2347

Reading the pull request milestone, 3.4.0 is the first version that has this fixed, although I recommend updating to 3.7.0.

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. domain/schema Issue in the "Schema" domain: Prisma Schema, Introspection, Migrations etc. kind/bug A reported bug. topic: validation
Projects
None yet
Development

No branches or pull requests

4 participants