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

SQL Server: Unable to rename a column referenced by a relation #8539

Closed
pimeys opened this issue Aug 2, 2021 · 0 comments · Fixed by prisma/prisma-engines#2118
Closed

SQL Server: Unable to rename a column referenced by a relation #8539

pimeys opened this issue Aug 2, 2021 · 0 comments · Fixed by prisma/prisma-engines#2118
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/schema Issue for team Schema. tech/engines/migration engine Issue in the Migration Engine topic: sql server Microsoft SQL Server
Milestone

Comments

@pimeys
Copy link
Contributor

pimeys commented Aug 2, 2021

Bug description

Renaming e.g. an id column that is referenced in a relation, will lead to a database error:

Error querying the database: 'There is already an object named 'FK__Post__authorId' in the database.' on server 6fb6df574dfa executing  on line 1 (code: 2714, state: 5, class: 16)

How to reproduce

Starting with the following data model, pushing it to the database:

model Post {
  id        Int     @default(autoincrement()) @id
  author    User?   @relation(fields: [authorId], references: [id])
  authorId  Int?
}

model User {
  id      Int     @default(autoincrement()) @id
  posts   Post[]
}

Next, we rename the id field of the User model to uId, changing the references: [id] to references: [uId] in the Post's author relation:

model Post {
  id        Int     @default(autoincrement()) @id
  author    User?   @relation(fields: [authorId], references: [uId])
  authorId  Int?
}

model User {
  uId      Int     @default(autoincrement()) @id
  posts    Post[]
}

Pushing this schema will lead to the error mentioned above.

Expected behavior

It should drop the key first, then create a new one.

Environment & setup

  • OS: The Best OS (Linux ftw)

Prisma Version

latest master on 2.8.2021.

@pimeys pimeys added kind/bug A reported bug. tech/engines/migration engine Issue in the Migration Engine topic: sql server Microsoft SQL Server labels Aug 2, 2021
@pimeys pimeys added this to the 2.29.0 milestone Aug 2, 2021
@janpio janpio added the team/schema Issue for team Schema. label Aug 2, 2021
@pantharshit00 pantharshit00 added the bug/2-confirmed Bug has been reproduced and confirmed. label Aug 2, 2021
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/schema Issue for team Schema. tech/engines/migration engine Issue in the Migration Engine topic: sql server Microsoft SQL Server
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants