This might help: https://www.prisma.io/docs/concepts/components/prisma-schema/relations/referential-actions

🌐
Reddit
reddit.com › r/node › prisma foreign key constraint error after merging user & admin into 1 table
r/node on Reddit: prisma foreign key constraint error after merging user & admin into 1 table
January 23, 2024 -

I was handling authorization like this that i make a model for users and model for admin and each one has an email and password but now i am trying to refactor my code by merging users and admin into 1 table and handle auths like below

model all_users {   
id       String   @id @default(uuid())   
name     String   
email    String   
@unique(map: "user_email_key")   
password String   
role     String   
createdAt DateTime @default(now())   
updatedAt DateTime @updatedAt    
user user?   admin       
admin?       
}  

model user{     
id           String?     
alluserId String?     @unique     
user         all_users ?     @relation(fields: [userId], references: [id])    
votes     votes[] 
} 

model admin{     
id           String?     
alluserId String?    @unique     user         
all_users ?     @relation(fields: [userId], references: [id])      
votes     votes[] 
} 

model votes{     
id                  String        @id @default(uuid())     
votes          Json?     
user user @relation(fields: [userId], references: [alluserId])     
userId String     
admin        admin    @relation(fields: [adminId], references: [alluserId])     
adminId      String     
createdAt           DateTime  @default(now())     
updatedAt           DateTime  @updatedAt      @@index([entrepreneurId], name: "index_votes") }

when I use npx prisma db push on a new database it works great but now when I try to make npx prisma db push on my old database so I can use votes i always get this error

insert or update on table "votes" violates foreign key constraint "votes_userId_fkey" 0: sql_schema_connector::apply_migration::migration_step

Discussions

Error: Database error: Foreign key constraint failed
I have the following schema: · I execute: npx prisma db push More on github.com
🌐 github.com
23
May 8, 2021
Bug (D1): PrismaClientKnownRequestError: Foreign key constraint failed on the field: `foreign key`
Bug description When using Cloudflare D1 and performing an action which would break a foreign key constraint, the field in the error message and in the meta object is always foreign key instead of ... More on github.com
🌐 github.com
4
May 26, 2024
ERROR: Foreign key constraint failed on the field
Bug description I am getting the error " Foreign key constraint failed on the field: `OrderProduct_sku_fkey (index)" This issue happens when I try to create a relationship between Product and Order... More on github.com
🌐 github.com
1
April 13, 2023
Prisma incorrectly parses CRDB's FK constraint error as `not available`
Bug description We are seeing errors like Foreign key constraint failed on the field: `(not available)` and was wondering whether it’s possible to surface which FK is causing this error. Some table... More on github.com
🌐 github.com
3
May 3, 2024
🌐
GitHub
github.com › prisma › prisma › issues › 19430
The solution to the discussion gives a "Foreign key constraint failed on the field: ..." error when I try to connect an existing record referenced by the bookId field. Connecting a book while creating a Like object gives me a "Foreign key constraint failed on the field: like_comment_fk (index)`" error and vice-versa · Issue #19430 · prisma/prisma
May 24, 2023 - @relation(fields: [bookId], references: [id], name: "book") comment Comment? @relation(fields: [bookId], references: [id], name: "comment") ERROR:Error parsing attribute "@relation": The given constraint name Like_bookId_fkey has to be unique in the following namespace: global for foreign keys.
Author   prisma
🌐
GitHub
github.com › prisma › prisma › issues › 6995
Error: Database error: Foreign key constraint failed · Issue #6995 · prisma/prisma
May 8, 2021 - @relation(fields: [id], references:[entityId]) } model Address { entityId String @id city String? line1 String? line2 String? postalCode String? user User? } I execute: npx prisma db push · I am using: Postgres · The error I get: Error: Database error Foreign key constraint failed: User_id_fkey 0: sql_migration_connector::sql_database_step_applier::apply_migration at migration-engine/connectors/sql-migration-connector/src/sql_database_step_applier.rs:15 1: migration_core::api::SchemaPush at migration-engine/core/src/api.rs:163 ·
Author   prisma
🌐
GitHub
github.com › prisma › prisma › issues › 24293
Bug (D1): PrismaClientKnownRequestError: Foreign key constraint failed on the field: `foreign key` · Issue #24293 · prisma/prisma
May 26, 2024 - Bug description When using Cloudflare D1 and performing an action which would break a foreign key constraint, the field in the error message and in the meta object is always foreign key instead of the actual field. This makes debugging t...
Author   prisma
🌐
GitHub
github.com › prisma › prisma › issues › 18723
ERROR: Foreign key constraint failed on the field · Issue #18723 · prisma/prisma
April 13, 2023 - Foreign key constraint failed on the field: `OrderProduct_sku_fkey (index)` to link both models Product and OrderProduct through "sku" // Add your schema.prisma // This is your Prisma schema file, // learn more about it in the docs: https://pris.ly/d/prisma-schema generator client { provider = "prisma-client-js" } datasource db { provider = "postgresql" url = env("DATABASE_URL") } model Vendor { id Int @id @default(autoincrement()) name String website String address String?
Author   prisma
🌐
GitHub
github.com › prisma › prisma › issues › 24072
Prisma incorrectly parses CRDB's FK constraint error as `not available` · Issue #24072 · prisma/prisma
May 3, 2024 - When running the query manually, CRDB throws the following error, which suggests that Prisma is not parsing the FK name correctly. ERROR: insert on table "WearablePart" violates foreign key constraint "WearablePart_wearableId_fkey" Detail: Key (wearableId)=('foo') is not present in table "Wearable". ... Fails on any schema, repro steps above.
Author   prisma
🌐
DEV Community
dev.to › codarbind › foreign-key-constraint-failed-on-the-field-prisma--2bl3
Foreign key constraint failed on the field (prisma ) - DEV Community
October 19, 2022 - This can also happen when using upsert, in our case we had a prisma @relation tied to a foreign key/FK whose OnUpdate ReferentialAction was not changed from the default NoAction. The rather generic error message Foreign key constraint failed on the field:fk_ <..> (index)` doesn't help much on pinpointing the cause or any direction whatsoever.
Find elsewhere
🌐
Prisma
prisma.io › home › error reference › error reference › error reference
Errors | Prisma Documentation
"Foreign key constraint failed on the field: {field_name}" "A constraint failed on the database: {database_error}" "The value {field_value} stored in the database for the field {field_name} is invalid for the field's type" "The provided value {field_value} for {model_name} field {field_name} is not valid" "Data validation error {database_error}" "Failed to parse the query {query_parsing_error} at {query_position}" "Failed to validate the query: {query_validation_error} at {query_position}" "Raw query failed.
🌐
GitHub
github.com › prisma › prisma › issues › 16029
Prisma Client: Improving foreign key constraint error messages · Issue #16029 · prisma/prisma
October 27, 2022 - This error message lacks which table the field was constrained. I think I have an issue in my cascading dependencies, but the error message is cryptic and it points to an id that is already inside the main table which I'm trying to truncate with the deleteMany option. Have anyone been in this situation before? Error: Invalid `prisma.slot.deleteMany()` invocation: Foreign key constraint failed on the field: `slot_id` Serialized Error: { "clientVersion": "4.3.1", "code": "P2003", "meta": { "field_name": "slot_id", }, } model Slot { id Int @id @default(autoincrement()) attendanceType String @map(
Author   prisma
🌐
GitHub
github.com › prisma › prisma › issues › 20659
Foreign key constraint failed when using createMany · Issue #20659 · prisma/prisma
August 11, 2023 - PrismaClientKnownRequestError: Invalid `prisma.quantity.createMany()` invocation in C:\Users\santosh.passoubady\Desktop\work\code\ProjectPipelineV2\push_to_db\push_main.ts:29:51 26 skipDuplicates: true, 27 }); 28 → 29 const upsertPartQty = await prisma.quantity.createMany( Foreign key constraint failed on the field: `(not available)` at Rn.handleRequestError (C:\Users\santosh.passoubady\Desktop\work\code\ProjectPipelineV2\push_to_db\node_modules\@prisma\client\runtime\library.js:174:7325) at Rn.handleAndLogRequestError (C:\Users\santosh.passoubady\Desktop\work\code\ProjectPipelineV2\push_to_db\node_modules\@prisma\client\runtime\library.js:174:6754) at Rn.request (C:\Users\santosh.passoubady\Desktop\work\code\ProjectPipelineV2\push_to_db\node_modules\@prisma\client\runtime\library.js:174:6344) { code: 'P2003', clientVersion: '4.16.2', meta: { field_name: '(not available)' } }
Author   prisma
🌐
Stack Overflow
stackoverflow.com › questions › 75428539 › prisma-error-while-creating-foreign-key-constraint-failed-on-the-field-forei
Prisma Error while creating - Foreign key constraint failed on the field: `foreign key`
@relation(fields: [article_id], references: [articleID]) } model Articlelist { id Int @id @default(autoincrement()) articleID Int @unique article_desc String Prices Prices[] } ... Invalid `prisma.articles.create()` invocation: Foreign key constraint failed on the field: `foreign key`
🌐
GitHub
github.com › prisma › prisma › issues › 18058
Optional relationship creates foreign key constraint · Issue #18058 · prisma/prisma
February 23, 2023 - Bug description Optional relationships create a foreign key constraint, producing this error. Note I had previously had this set as a non-optional relationship, but have since migrated away from that. Invalid `prisma.author.create()` inv...
Author   prisma
🌐
GitHub
github.com › prisma › prisma › issues › 15722
Foreign Key Constraint - Create Record · Issue #15722 · prisma/prisma
October 9, 2022 - Error: private async loadTickets() { → 12 this.client.db.commission.create( Foreign key constraint failed on the field: `clientUserId` at RequestHandler.handleRequestError (C:\Users\josep\OneDrive\Desktop\Bots\Navi\node_modules\@prisma\client\runtime\index.js:29909:13) at RequestHandler.request (C:\Users\josep\OneDrive\Desktop\Bots\Navi\node_modules\@prisma\client\runtime\index.js:29892:12) at async PrismaClient._request (C:\Users\josep\OneDrive\Desktop\Bots\Navi\node_modules\@prisma\client\runtime\index.js:30864:16) { code: 'P2003', clientVersion: '4.3.1', meta: { field_name: 'clientUserId' } } Run the code linked above, attempting to create a record that has a relational field.
Author   prisma
🌐
GitHub
github.com › prisma › prisma › issues › 22094
Foreign key constraint fail depending on a specific order of objects in data · Issue #22094 · prisma/prisma
Bug description When I tried to update an entity I received Foreign key constraint failed on the field: work_id. But it only happens when i put my update data objects in a particular order. e.g prisma.update({where: {id}}, {data: { work:...
Author   prisma