```model Profile { id String @id @default(cuid()...
# orm-help
m
Copy code
model Profile {
  id String @id @default(cuid())
  name String
  address String
  image blob
  created_at DateTime @default(now())
  updated_at DateTime @updatedAt
}

model Token {
  id String @id @default(cuid())
  profile_id Profile[]
  featured_status Boolean
  category String
  file blob
  description String
  info String
  type String
  last_selling_price Float
  ownership_chain String
  created_at DateTime @default(now())
  updated_at DateTime @updatedAt
}
Hello I am trying to add one to many relation (one profile can have many tokens) but I think this isn't correct. Also code editor giving me red lines on blob type and bytea for storing images.
n
Hey Muhammad 👋 I am assuming that you are using PostgreSQL as you mentioned
bytea
type but I cannot see any field having bytea type in the above schema. For the one to many relations you are looking for something like this:
Copy code
model Profile {
  id         String   @id @default(cuid())
  name       String
  address    String
  image      blob
  created_at DateTime @default(now())
  updated_at DateTime @updatedAt
  Token      Token[]
}

model Token {
  id                 String   @id @default(cuid())
  featured_status    Boolean
  category           String
  file               blob
  description        String
  info               String
  type               String
  last_selling_price Float
  ownership_chain    String
  created_at         DateTime @default(now())
  updated_at         DateTime @updatedAt
  profileId          String
  profile            Profile? @relation(fields: [profileId], references: [id])
}
d
@Nurul should it be image bytea? Is it ok to store images in a postgres dB?
n
You could store images in PostgresDB by converting it into base64, but generally it is recommended to store images in a Blob Storage like AWS S3 and then store the reference to the image in your database.