How to use DECIMAL(10,2) in prisma migrate tool?
Asked Answered
H

2

12

I need save DECIMAL(10,2) in database. In MySQL there is DECIMAL type.

MySQL docs:

https://dev.mysql.com/doc/refman/8.0/en/fixed-point-types.html

Prisma 2.0 docs:

https://www.prisma.io/docs/reference/database-connectors/mysql

Possible Prisma 2.0 flows:

https://www.prisma.io/docs/understand-prisma/introduction#typical-prisma-workflows

  • I am using Prisma Migrate flow and see that mapping is constrained.
  • I see that it can be done in Introspection flow.

Are there any plans of support mysql data types like DECIMAL(10,2) in Prisma Migrate flow?

Hanschen answered 26/4, 2020 at 23:23 Comment(0)
R
16

Full support for native types has been added in prisma/[email protected]

datasource db {
  provider = "mysql"
  url      = env("DATABASE_URL")
}

generator client {
  provider = "prisma-client-js"
}
 
model Product {
  id Int @id @default(autoincrement())
  code String
  price Decimal @db.Decimal(9,2)
}
Reflector answered 3/9, 2021 at 5:16 Comment(0)
I
0

Currently prisma migrate doesn't support the Decimal type. You can track the issue for custom DB types here

As a workaround, you would have to use a custom migration tool and specify the Decimal field that you require and then run prisma introspect which will get all the fields from your DB and populate the schema.prisma.

Inearth answered 27/4, 2020 at 11:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.