faint-whiteF
Refine2y ago
6 replies
faint-white

Help Needed: Error Creating Profile - "'id' of relation 'Profile' violates not-null constraints

the code :
const { formProps, saveButtonProps, form } = useForm( { meta: { select: "*" }, onMutationSuccess: (response) => { console.log('data : ', response.data); handleUserCreationSuccess(response.data); } } ); const { mutate: createProfile } = useCreate(); const { mutate: updateUser } = useUpdate(); const handleUserCreationSuccess = async (userData: BaseRecord) => { const userId = await userData.id; console.log('userId : ', userId); // default profile is created on creation of the User createProfile({ resource: "Profile", values: { username: "", // Default values isEmailVerified: false, emailVerified: null, image: "", twitterUsername: "", twitterFollowers: 0, }, }, { onSuccess: (profileResponse) => { const profileId = profileResponse.data.id; console.log('profileId : ', profileId); // Update the user with the profile ID updateUser({ resource: "User", id: userId, values: { profileId, }, }); }, onError: (error) => { notification.error({ message: "Error", description: `Failed to create profile: ${error.message}`, }); } }); }; Schemas : model User { id Int @id @default(autoincrement()) name String? email String? @unique profileId String? role UserRole? profile Profile? @relation(fields: [profileId], references: [id] } model Profile { id String @id @default(cuid()) username String? isEmailVerified Boolean? emailVerified DateTime? image String? twitterUsername String? twitterFollowers Int? User User[] }
Was this page helpful?