5.5.5. Configure Data Model Properties

In this chapter, you’ll learn how to configure data model properties.

Property’s Default Value#

Use the default method on a property's definition to specify the default value of a property.

For example:

Code
1import { model } from "@medusajs/framework/utils"2
3const MyCustom = model.define("my_custom", {4  color: model5    .enum(["black", "white"])6    .default("black"),7  age: model8    .number()9    .default(0),10  // ...11})12
13export default MyCustom

In this example, you set the default value of the color enum property to black, and that of the age number property to 0.


Nullable Property#

Use the nullable method to indicate that a property’s value can be null.

For example:

Code
1import { model } from "@medusajs/framework/utils"2
3const MyCustom = model.define("my_custom", {4  price: model.bigNumber().nullable(),5  // ...6})7
8export default MyCustom

Unique Property#

The unique method indicates that a property’s value must be unique in the database through a unique index.

For example:

Code
1import { model } from "@medusajs/framework/utils"2
3const User = model.define("user", {4  email: model.text().unique(),5  // ...6})7
8export default User

In this example, multiple users can’t have the same email.

Was this chapter helpful?
Edit this page