npx prisma migrate dev doesnt update @relation
model Todo {
id String @id @default(cuid())
customer String
title String
address String?
location Json?
description String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
camera String[]
nakkilista Boolean @default(false)
status Status @default(OPEN)
creatorId String
organizationId String
contactNumber String?
setDate DateTime?
creator User @relation("CreatedTodos", fields: [creatorId], references: [uid])
organization Organization @relation("OrganizationTodos", fields: [organizationId], references: [id]) // EDITED this
assignedUsers User[] @relation("TodoAssignments")
}
model Organization {
id String @id @default(cuid())
name String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
ownerId String
Invite Invite[]
owner User @relation("OwnerOrganizations", fields: [ownerId], references: [uid])
todos Todo[] @relation("OrganizationTodos") // EDITED this
users User[] @relation("UserMemberships")
}
Already in sync, no schema change or pending migration was found.
✔ Generated Prisma Client (v6.1.0) to .\node_modules@prisma\client in 90ms
database is postresql 16
i added relation to my schema and it just wont go to database and i dont know anymore what to do? i have reseted my database but that doesnt help either, i added some extra field to schema and that did go to database but didnt update relations. I dont know if this is a bug but i hope its going to get fixed. I will now delete the whole database and start from the beginning6 Replies
HI @Abluux
When you run
migrate dev
, Prisma creates the necessary foreign key constraints in your PostgreSQL database to represent the relations defined in your schema. The message Already in sync, no schema change or pending migration was found
suggests that Prisma believes your database schema is already up to date with your Prisma schema.
Can you please share any error message you zre running into?i make my schema on backend and i do npx prisma db pull to get schema to frontend, this schema is not uptated to that
also getting typecript error when trying to disconnect assignedUsers from my todo
Object literal may only specify known properties, and 'assignedUsers' does not exist in type '(Without<TodoUpdateManyMutationInput, TodoUncheckedUpdateManyInput> & TodoUncheckedUpdateManyInput) | (Without<...> & TodoUpdateManyMutationInput)'.ts(2353)
index.d.ts(3290, 5): The expected type comes from property 'data' which is declared here on type '{ data: (Without<TodoUpdateManyMutationInput, TodoUncheckedUpdateManyInput> & TodoUncheckedUpdateManyInput) | (Without<...> & TodoUpdateManyMutationInput); where?: TodoWhereInput | undefined; }'
(property) assignedUsers: {
disconnect: {
uid: any;
};
await prisma.todo.updateMany({
where: { organizationId },
data: { assignedUsers: { disconnect: { uid: userToDisassociate } } },
});
i make my schema on backend and i do npx prisma db pull to get schema to frontend, this schema is not uptated to thatThe
prisma db pull
command is used to introspect your database and update your Prisma schema based on the current state of your database. Are you manually updating your database?
Regarding the TypeScript error when trying to disconnect assignedUsers:The error you're seeing suggests that the
assignedUsers
field is not recognized as a valid property for updating a Todo. This could be because the updateMany
operation doesn't support updating relations directly.
Instead of using updateMany
, you should use update for updating relations. Here's how you can modify your code:
This approach updates a single Todo and disconnects the specified user from the assignedUsers relation.
If you need to perform this operation on multiple Todos, you might need to use a transaction or a loop to update each Todo individually. await prisma.$transaction(async (prisma) => {
const todos = await prisma.todo.findMany({
where: { organizationId, assignedUsers: { some: { uid: userToDisassociate } } },
});
for (const todo of todos) {
await prisma.todo.update({
where: { id: todo.id },
data: { assignedUsers: { disconnect: { uid: userToDisassociate } } },
});
}
await prisma.organization.update({
where: { id: organizationId },
data: {
users: {
disconnect: { uid: userToDisassociate },
},
},
});
});
Something like this?Relation queries (Concepts) | Prisma Documentation
Prisma Client provides convenient queries for working with relations, such as a fluent API, nested writes (transactions), nested reads and relation filters.
Something like this?Yes, please