You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/200-orm/100-prisma-schema/20-data-model/30-indexes.mdx
+52Lines changed: 52 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,6 +42,10 @@ You can configure indexes, unique constraints, and primary key constraints with
42
42
- Available on the `@id`, `@@id`, `@unique`, `@@unique` and `@@index` attributes
43
43
- SQL Server only
44
44
45
+
- The [`map` argument](#configuring-the-name-of-indexes-with-map) allows you to specify a custom name for the index or constraint in the underlying database
46
+
- Available on the `@id`, `@@id`, `@unique`, `@@unique` and `@@index` attributes
47
+
- Supported in all databases
48
+
45
49
See the linked sections for details of which version each feature was first introduced in.
46
50
47
51
### Configuring the length of indexes with `length` (MySQL)
@@ -458,6 +462,54 @@ The default value of `clustered` for each attribute is as follows:
458
462
459
463
A table can have at most one clustered index.
460
464
465
+
### Configuring the name of indexes with `map`
466
+
467
+
The `map` argument allows you to specify a custom name for the index or constraint in the underlying database. This is useful when you want to use a specific naming convention or when the auto-generated name doesn't meet your requirements.
468
+
469
+
The `map` argument is available on the `@id`, `@@id`, `@unique`, `@@unique` and `@@index` attributes.
470
+
471
+
As an example, the following model configures a custom name for the index on the `title` field:
472
+
473
+
```prisma file=schema.prisma showLineNumbers
474
+
model Post {
475
+
id Int @id
476
+
title String
477
+
478
+
@@index([title], map: "my_custom_index_name")
479
+
}
480
+
```
481
+
482
+
This translates to the following SQL command (PostgreSQL example):
0 commit comments