Migrate: @unique does not work for columns using @map

Created on 3 Sep 2019  路  5Comments  路  Source: prisma/migrate

On a fresh instance of MySQL 5.7.14:

schema.prisma

model Foo {
  fooId String  @map("foo_uuid") @default(uuid()) @id
  barId String? @map("bar_uuid") @unique
}
prisma2 lift save
prisma2 lift up

Produces the following error:

Error: QueryError(QueryError(QueryError(MySqlError { ERROR 1072 (42000): Key column 'barId' doesn't exist in table }
bu2-confirmed kinbug

Most helpful comment

This is fixed in alpha and will be available today in the afternoon.

All 5 comments

Even just quickly looking at the error message again, I'm surprised that it's

Error: QueryError(QueryError(QueryError(MySqlError { ERROR 1072 (42000): Key column 'barId' doesn't exist in table }

Not:

Error: QueryError(QueryError(QueryError(MySqlError { ERROR 1072 (42000): Key column 'bar_uuid' doesn't exist in table }

Could this barId <> bar_uuid mapping be anything to do with it?

Maybe @map is not working, @pantharshit00 can you please help us validate this?

Ok, it does seem like it's the map which is a problem here. In the example below Foo1 and Foo2 work as expected. Foo3 does not.

I'll change the name of this Issue, hopefully should be quite a clear bug repro now.

Cheers!

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

generator photon {
  provider = "photonjs"
  output   = "../../../server/src/connections/platform-db"
}

// works
model Foo1 {
  fooId    String  @map("foo_uuid") @default(uuid()) @id
  bar_uuid String? @unique
}

// works
model Foo2 {
  fooId    String  @map("foo_uuid") @default(uuid()) @id
  bar_uuid String? @map("bar_uuid") @unique
}

// doesn't work
model Foo3 {
  fooId String  @map("foo_uuid") @default(uuid()) @id
  barId String? @map("bar_uuid") @unique
}

This is fixed in alpha and will be available today in the afternoon.

Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nickreynke picture nickreynke  路  4Comments

hamidb80 picture hamidb80  路  4Comments

sameoldmadness picture sameoldmadness  路  4Comments

ff-anthony-soto picture ff-anthony-soto  路  3Comments

julien1619 picture julien1619  路  4Comments