The error message you are seeing indicates that the data type of the arguments you are passing to the `prisma.createOneusuario` function is incorrect. Specifically, the `cpf` and `phone` arguments are expected to be of type `BigInt`, but you are passing them as strings [1].
To fix this error, you can use the following methods:
1. **Method 1**: Convert values to BigInt in your application code:
In this method, you convert the provided string values for "cpf" and "phone" to BigInt directly in your application code before passing them to the Prisma create function.
```javascript
const prisma = new PrismaClient();
const cpf = '12345678809';
const phone = '2786856445';
// Convert the strings to BigInt before inserting
const usuario = await prisma.usuario.create({
data: {
cpf: BigInt(cpf),
phone: BigInt(phone),
// Other fields here
}
});
// Close the Prisma client
prisma.$disconnect();
```
2. **Method 2**: Update Prisma schema to allow string values for BigInt fields:
In this method, you update your Prisma schema to allow string values for the "cpf" and "phone" fields by using the `@map` attribute to specify the database column type as text.
```prisma
model Usuario {
id Int @id @default(autoincrement())
cpf String @map("cpf") @unique
phone String @map("phone")
// Other user fields
}
```
With this schema, you can pass string values for "cpf" and "phone" when creating a new user, and Prisma will automatically convert them to BigInt when storing them in the database.
3. **Method 3**: Use a Prisma transform to handle the conversion:
You can also use a Prisma transform to handle the conversion between string and BigInt values. This method is more abstract and can be reusable across your application.
Define a Prisma transform in your schema.prisma file:
```prisma
generator client {
provider = "prisma-client-js"
output = "./generated/client"
target = "queryEngine"
previewFeatures = ["stringTransformer"]
}
model Usuario {
id Int @id @default(autoincrement())
cpf String @transform.stringToBigInt @unique
phone String @transform.stringToBigInt
// Other user fields
}
```
Use the transform in your code:
```javascript
const prisma = new PrismaClient();
const cpf = '12345678809';
const phone = '2786856445';
const usuario = await prisma.usuario.create({
data: {
cpf: cpf,
phone: phone,
// Other fields here
}
});
// Close the Prisma client
prisma.$disconnect();
```
With the Prisma transform, you abstract the conversion logic, making it more reusable and keeping your schema cleaner.