New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
You cannot define an index on fields with Native type Text of MySQL. #8661
Comments
This infers an index on a TEXT column with a length limit as a normal index which is why it's not currently working. We would need to design a PSL solution for defining specific kinds of indices, which is a feature we haven't picked up just yet. The current workaround is definitely not nice: We'll update this issue as soon as we start looking into a sustainable solution. |
Feature issue tracking this: #7263 |
This is something that should work with the upcoming 3.5.0 version using the generator client {
provider = "prisma-client-js"
previewFeatures = ["extendedIndexes"]
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
model av {
avid Int @id @default(autoincrement()) @db.UnsignedInt
av_desc String? @db.Text
@@index([av_desc(length: 100)], name: "av_desc")
} |
Can you try to introspect your database again with 3.5.0 @jamiev-dfm? That should create a slightly different schema file that does include the |
Ping @jamiev-dfm |
I got a similar error in another way so I'll keep a record here. Running Prisma schema loaded from prisma/schema.prisma
Error: Schema parsing
error: You cannot define an index on fields with Native type Text of MySQL. If you are using the `extendedIndexes` preview feature you can add a `length` argument to allow this.
--> schema.prisma:152
|
151 |
152 | model FilmText {
153 | film_id Int @id @db.SmallInt
154 | title String @db.VarChar(255)
155 | description String? @db.Text
156 |
157 | @@index([title, description], map: "idx_title_description")
158 | @@map("film_text")
159 | }
|
generator client {
provider = "prisma-client-js"
previewFeatures = ["fullTextSearch", "fullTextIndex", "extendedIndexes"]
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
model FilmText {
film_id Int @id @db.SmallInt
title String @db.VarChar(255)
description String? @db.Text
@@fulltext([title, description], map: "idx_title_description")
@@map("film_text")
} |
Could you successfully use that schema afterwards @masashi-sutou? |
I got the same error too. I converted the Text fields to VarChar type. |
With Prisma 4 next week we will stabilize the This will also include a (hopefully) helpful error message when you are not using We consider this problem solved then 🥳 Please let us know if you disagree or this does not work as expected for you. Thanks! |
Bug description
My database has indices on a few text fields, and introspecting it put those indices in the schema, but
prisma validate
says "You cannot define an index on fields with Native type Text of MySQL.".This error was also mentioned in #5288 and apparently fixed, but I'm still seeing it.
How to reproduce
I've included a minimal schema below. Just put that in a file and validate it.
Expected behavior
The schema seems correct to me, so I think it should validate without errors, otherwise the introspection shouldn't output the index.
Prisma information
Environment & setup
Prisma Version
The text was updated successfully, but these errors were encountered: