Feature Request: Add a PK field to prisma generated mapping tables
See original GitHub issueHi,
I’m using a managed DB hosting provider (OVH) and in turn have no control over the sql_require_primary_key
setting. When importing the prisma generated DB, I get an error saying each table must have a primary key. For the most part, this is fine but I’m struggling with the tables that prisma creates as mapping tables.
Take this model:
model User {
id Int @id @default(autoincrement())
canActAs User[] @relation("actingAs", references: [id])
hasActingAs User[] @relation("actingAs", references: [id])
}
Prisma will create a _actingAs
table with 2 columns, A
and B
. I need to be able to add a PK field to that table.
Note: I tried creating an empty migration which altered those mapping tables adding a PK field but it created a new migration removing it after because the schema was out of line.
Note: Initially, I didn’t think those tables were causing my error because when I look at the _actingAs
mapping table, I do see that both columns A
and B
are down as PK fields:
but the following query raises them as not having a PK field:
select tab.table_schema as database_name,
tab.table_name
from information_schema.tables tab
left join information_schema.table_constraints tco
on tab.table_schema = tco.table_schema
and tab.table_name = tco.table_name
and tco.constraint_type = 'PRIMARY KEY'
where tco.constraint_type is null
and tab.table_schema not in('mysql', 'information_schema',
'performance_schema', 'sys')
and tab.table_type = 'BASE TABLE'
-- and tab.table_schema = 'sakila' -- put schema name here
order by tab.table_schema,
tab.table_name;
_Originally posted by @webnoob in https://github.com/prisma/prisma/discussions/11028_
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
Indeed, that’s my assessment too. It was baffling me at first.
Do you mean the SQL to create the actingAs table?
With regards to the comment which confused you. What I mean is that when I look in MySQL workbench, it shows both columns A and B as PK :
Note: I’ve since updated my table names so _acting_as is replacing actingAs.