Error if primary key is a reference
See original GitHub issueHi! Thx for a great lib!
I’m moving a project which has around 100 tables to typescript and it seems that I have only one error from kanel after initial types generation and little adjusting of customTypeMap
. Let’s consider following DB schema:
pageTiles.sql
-- auto-generated definition
create table "pageTiles" (
"pageId" uuid not null
constraint "pageTiles_pageId_fkey"
references pages
on delete cascade,
"tileId" uuid not null,
"tileType" varchar(50) not null,
constraint "pageTiles_pkey"
primary key ("pageId", "tileId", "tileType")
);
create unique index "pageTiles_tileId_key"
on "pageTiles"("tileId");
componentFormTiles.sql
-- auto-generated definition
create table "componentFormTiles" (
id uuid default public.gen_random_uuid() not null
constraint "componentFormTiles_pkey"
primary key
constraint "componentFormTiles_id_fkey"
references "pageTiles"("tileId")
on update cascade on delete cascade
deferrable
);
pageTiles.ts
take a look at tileId
// Automatically generated. Don't change this file manually.
import { PagesId } from './pages';
export default interface PageTiles {
/**
* Index: pageTiles_pageId_tileId_key
* Index: pageTiles_pageId_tileOrder_unique
* Index: pageTiles_pageId_uri_unique
* Primary key. Index: pageTiles_pkey
*/
pageId: PagesId;
/**
* Index: pageTiles_pageId_tileId_key
* Primary key. Index: pageTiles_pkey
* Index: pageTiles_tileId_key
*/
tileId: string;
/** Primary key. Index: pageTiles_pkey */
tileType: string;
}
componentFormTiles.ts
first import is not correct - there is no such export in pageTiles.ts
// Automatically generated. Don't change this file manually.
import { PageTilesId } from './pageTiles'; // <--- ERROR!
import { FormsId } from './forms';
export type ComponentFormTilesId = string & { __flavor?: 'componentFormTiles' };
export default interface ComponentFormTiles {
/** Primary key. Index: componentFormTiles_pkey */
id: ComponentFormTilesId;
}
Could you suggest any workaround?
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
There are no primary or candidate keys in the referenced table ...
You are getting an error because your PK consists of three columns but you are attempting to reference it with only one column....
Read more >3 common foreign key mistakes (and how to avoid them)
1. Mismatched data types. When you're using a foreign key to reference a column in another table, the datatypes of both tables have...
Read more >The referenced table must have a primary or candidate key ...
This issue is caused by that the column list specified in the statement for adding foreign key is different from the column list...
Read more >Primary Key and Foreign Key Errors to Avoid - DATAVERSITY
A foreign key is a reference to a unique identifier. Theoretically the reference should be to a primary key and not some other...
Read more >13.1.17.5 FOREIGN KEY Constraints - MySQL :: Developer Zone
NDB requires an explicit unique key (or primary key) on any column referenced as a foreign key. InnoDB does not, which is an...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @jifeon, I’ve published a new version that supports hooks. Your specific issue is not yet resolved but I’ve streamlined things a bit so it should be easier for me to test and fix, so I will get around to that. But for now you should be able to work around the issue with a hook.
Thank you @kristiandupont!
I’m not working with that project any more, so can’t check. @frenzzy you probably want to check it out!