I'm testing prisma in a remix.js application.
So I have the following MySQL table for Users
desc Users;
+-----------+-------------+------+-----+---------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------------------+----------------+
| uid | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(45) | NO | UNI | NULL | |
| email | varchar(45) | NO | UNI | NULL | |
| password | varchar(99) | NO | | NULL | |
| CreatedAt | datetime | NO | | current_timestamp() | |
| status | tinyint(4) | YES | | 1 | |
+-----------+-------------+------+-----+---------------------+----------------+
Using after install and do the first introspection, I've added the last column that suposed to be a Boolean but MariaDB converts it as TinyInt(1). So far so good. Then, after it, I did a new prisma db pull and my Users Schema is now:
model Users {
uid Int @id @unique(map: "id_UNIQUE") @default(autoincrement())
name String @unique(map: "name_UNIQUE") @db.VarChar(45)
email String @unique(map: "email_UNIQUE") @db.VarChar(45)
password String @db.VarChar(99)
CreatedAt DateTime @default(now()) @db.DateTime(0)
status Int? @default(1) @db.TinyInt
enderecos enderecos[]
}
The problem happens when I try to retrieve data. If a do a console.log of a simple Users.findMany() i get:
[
{
name: 'lada',
email: '[email protected]',
CreatedAt: '2023-05-11T21:35:02.000Z',
uid: 1,
password: '$2a$12$WXIy/aWr6Y12Y08SBcUeWOCVZ6S4GBK/EZeGpm0j5FF4yUAF7ATFa'
},
{
name: 'teste',
email: '[email protected]',
CreatedAt: '2023-05-11T21:38:47.000Z',
uid: 2,
password: '$2a$12$FXSAGgkAMWZhAhPwVMhQYOCCAZFqGCFXm9aQSe3QbQXL56v9cptv2'
},
{
name: 'James Bond',
email: '[email protected]',
CreatedAt: '2023-05-15T06:34:33.000Z',
uid: 3,
password: '$2a$12$WelH9VyYBoOSYXFbW7/9N.dKIEnWnTQ6tKUOGYqISqWTpma0wEiPO'
},
{
name: 'John Smith',
email: '[email protected]',
CreatedAt: '2023-05-15T06:40:18.000Z',
uid: 4,
password: '$2a$12$hpxIuxyQTXzaLpBT3PwVFOhVQiuYU5ncQw1UnV038rCYg6GKAx1AK'
}
]
without the 'status' column.
And when creating a new User I force to insert the status column const users = await prisma.Users.create({data: {name, email, password: hashedPassword, status: 1}});
I get the following error:
18
19 const hashedPassword = await hash(password, 12);
20
→ 21 const users = await prisma.Users.create({
data: {
name: 'John Snow',
email: '[email protected]',
password: '$2a$12$uppcEWaYGH8RtC1o/PMTpuoFPeQ3S21or96LysLFAeRnnFRnUI2Da',
status: 1
~~~~~~
}
})
Unknown arg `status` in data.status for type UsersCreateInput. Did you mean `name`? Available args:
type UsersCreateInput {
name: String
email: String
CreatedAt?: DateTime
password: String
enderecos?: enderecosCreateNestedManyWithoutUsersInput
}
I see there is not status in the type UsersCreateInput
but I'm using javascript, and I don't know where or if I could edit this type.
Any ideas?
Thanks!
Ok, nothing like write a complete question to realize how stupid I am!
After applying prisma db pull
I forgot to regenerate the Prisma Client.
So the solution is:
npx prisma db pull
npx prisma generate