question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error if primary key is a reference

See original GitHub issue

Hi! 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:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kristiandupontcommented, Oct 5, 2020

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.

0reactions
jifeoncommented, Aug 21, 2022

Thank you @kristiandupont!

I’m not working with that project any more, so can’t check. @frenzzy you probably want to check it out!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found