Please, Please help me. This is killing my time. ...
# orm-help
p
Please, Please help me. This is killing my time. this is my model for User:
Copy code
model User {
  id                          String                      @id @default(cuid())
  password                    String?                     @db.VarChar(255)
  phoneNumber                 String                      @unique
  createdAt                   DateTime?                   
  updatedAt                   DateTime?                    
  deletedAt                   DateTime?
}
and when I do this:
Copy code
await prisma.user.create({
        data: {
          password: "password",
          phoneNumber: "+4081824712",
        },
      });
I get this error:
Copy code
Invalid `prisma.user.create()` invocation:

{
  data: {
    createdAt: '2021-06-30T00:41:32Z',
+   phoneNumber: String,
?   id?: String,
?   password?: String | null,
?   updatedAt?: DateTime | null,
?   deletedAt?: DateTime | null
  }
}

Argument phoneNumber for data.phoneNumber is missing.

Note: Lines with + are required, lines with ? are optional.
m
Hey 👋🏼 sorry to hear you’re running into this issue 😕 It’s weird.. because in the error it says
phoneNumber
is missing but you’re passing it 🤔
Do you mind sharing more details about your setup? Which version of Prisma are you on?
p
im using the latest version.
i know..
this is pretty much about it… im using typegraphql by any chance. But i think it does not have anything to do with this problem. I did yarn prisma migrate … as well.
should I downgrade and try it again? if so what version should i install? 😞
m
I tried it and everything works (v2.26)
maybe try deleting your
node_modules
folder and running
npm i && npx prisma generate
?
nothing is wrong with your schema
p
i dont have to do npx prisma migrate dev --name init?
I will try first! thank you
m
if you did it once before then no
also you should consider updating the
createdAt
and
updatedAt
fields in your schema to this :
Copy code
createdAt DateTime @default(now())
 updatedAt DateTime @updatedAt
This way you don’t have to worry about passing them when using
create()
or
update()
p
its still giving me the same error 😞 can I share you my entire schema ?
oh and speaking of createdAt and updatedAt, im using middleware for utc timestamp (using moment):
Copy code
// Timestamp middleware
prisma.$use(async (params, next) => {
  if (params.action === "create") {
    params.args["data"] = { createdAt: timestamp() };
  }

  if (params.action === "createMany") {
    if (params.args.data !== undefined) {
      params.args.data["createdAt"] = timestamp();
    } else {
      params.args["data"] = { createdAt: timestamp() };
    }
  }

  if (params.action === "update") {
    params.args["data"] = { updatedAt: timestamp() };
  }

  if (params.action === "updateMany") {
    if (params.args.data !== undefined) {
      params.args.data["updatedAt"] = timestamp();
    } else {
      params.args["data"] = { updatedAt: timestamp() };
    }
  }

  if (params.action === "delete") {
    params.action = "update";
    params.args["data"] = { deletedAt: timestamp() };
  }

  if (params.action === "deleteMany") {
    params.action = "updateMany";
    if (params.args.data !== undefined) {
      params.args.data["deletedAt"] = timestamp();
    } else {
      params.args["data"] = { deletedAt: timestamp() };
    }
  }

  return next(params);
});
j
Looks to me that the middleware is deleting all other
data
values.
After
params.args["data"] = { createdAt: timestamp() };
the
data
object` only has the
createdAt
.
You'll want to just add the
createdAt
property, not replace the whole object.
m
can I share you my entire schema ?
Sure
p
@Mahmoud Thank you for helping me sir. I found the problem causing the issue. It was the middleware the caused the issue.@janpio Thank you. That was the problem of mine 🙂
🙌 2