I am using mySQL as a database and Prisma as an ORM and basically need to store Time objects without the Date part, eg '1:12.55', '12.53', '0.59'
I tried to model my table in schema.prisma file like this:
model Result {
attempt1 DateTime
}
Which resulted in the migration:
CREATE TABLE `Result` (
`date` DATETIME() NOT NULL
}
How do I modify my schema.prisma content so that it creates a migration with time field type instead of date ?
If you store a time bigger than 24 hours, you will need to use a DateTime. If you want another way to store time, you could use an Integer and then store a Unix Timestamp. This is one of the way I use if needed.
If you are looking for something else, I do not understand what it is. Maybe you could look in the documentation for something similar?
To store only the date portion you could use the native @db.date attribute. That would just store the date and not store the time.
In your schema file you could update the model as below to just store the date portion:
model modelName {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @db.Date
lastNumber Int
}
Here's a reference to Prisma's MySQL DateTime attribute: Reference
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.