# Foreign keys as primary values \[Apr 19\]

**URL:** https://community.nocodb.com/t/foreign-keys-as-primary-values-apr-19/370
**Category:** Discord-Discussions
**Created:** [November 3, 2022, 8:58am UTC](https://community.nocodb.com/t/foreign-keys-as-primary-values-apr-19/370 "2022-11-03T08:58:43Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![NocoDB](https://avatars.discourse-cdn.com/v4/letter/n/6f9a4e/32.png) [@NocoDB](https://community.nocodb.com/u/NocoDB)
#### Post date: [November 3, 2022, 8:58am UTC](https://community.nocodb.com/t/foreign-keys-as-primary-values-apr-19/370/1 "2022-11-03T08:58:43Z")

</div>

> 🙋‍♂️ **Harbard** _asked_

## Hi, it’s me again !

#### So I’m using my DB to handle translation, and I’d like to set foreign keys as primary values to avoid getting IDs in my tables.

#### 

#### I see in the code [https://github.com/nocodb/nocodb/blob/master/packages/nc-gui/components/project/spreadsheet/components/virtualHeaderCell.vue#L69](https://github.com/nocodb/nocodb/blob/master/packages/nc-gui/components/project/spreadsheet/components/virtualHeaderCell.vue#L69) that the `setAsPrimaryValue` is not available for foreign keys, is there a technical reason. Is it worth that I spend some time trying to implement this in a PR ?

#### 

#### ```sql

#### drop table if exists labels cascade;

#### CREATE TABLE labels (

#### id serial primary key,

#### en text,

#### fr text,

#### de text

#### );

#### 

#### drop table if exists schools cascade;

#### CREATE TABLE schools (

#### id serial primary key,

#### school\_label int references labels(id)

#### );

#### 

#### drop table if exists class\_rooms cascade;

#### CREATE TABLE class\_rooms (

#### id serial primary key,

#### class\_label int references labels(id),

#### school\_id int references schools(id)

#### );

#### 

#### drop table if exists students cascade;

#### CREATE TABLE students (

#### id serial primary key,

#### std\_label int references labels(id),

#### class\_id int references class\_rooms(id)

#### );

#### 

#### INSERT INTO public.labels (en,fr,de) VALUES

#### (‘school\_1’,‘ecole\_1’,NULL),

#### (‘school\_2’,‘ecole\_2’,NULL),

#### (‘class\_1’,‘classe\_1’,NULL),

#### (‘class\_2’,‘classe\_2’,NULL),

#### (‘class\_3’,‘classe\_3’,NULL),

#### (‘std\_1’,‘eleve\_1’,NULL),

#### (‘std\_2’,‘eleve\_2’,NULL),

#### (‘std\_3’,‘eleve\_3’,NULL),

#### (‘std\_4’,‘eleve\_4’,NULL),

#### (‘std\_5’,‘eleve\_5’,NULL);

#### 

#### INSERT INTO public.schools (school\_label) VALUES

#### (1),

#### (2);

#### 

#### INSERT INTO public.class\_rooms (class\_label,school\_id) VALUES

#### (3,1),

#### (4,1),

#### (5,2);

#### 

#### INSERT INTO public.students (std\_label,class\_id) VALUES

#### (6,1),

#### (7,1),

#### (8,2),

#### (9,3),

#### (10,3);

#### ```

 ![image0](https://canada1.discourse-cdn.com/flex011/uploads/nocodb/original/1X/6055a0a22cf4cef05ecd64cc2c7fb1958702af4e.png)

---

<div class="post-metadata">

### Author: ![NocoDB](https://avatars.discourse-cdn.com/v4/letter/n/6f9a4e/32.png) [@NocoDB](https://community.nocodb.com/u/NocoDB)
#### Post date: [November 3, 2022, 8:58am UTC](https://community.nocodb.com/t/foreign-keys-as-primary-values-apr-19/370/2 "2022-11-03T08:58:46Z")

</div>

> 💁 **o1lab** _replied_

#### The idea of foreign key is mostly for machines 🙂 and hence we are avoiding that to be set as primary values

#

---

<div class="post-metadata">

### Author: ![NocoDB](https://avatars.discourse-cdn.com/v4/letter/n/6f9a4e/32.png) [@NocoDB](https://community.nocodb.com/u/NocoDB)
#### Post date: [November 3, 2022, 8:58am UTC](https://community.nocodb.com/t/foreign-keys-as-primary-values-apr-19/370/3 "2022-11-03T08:58:47Z")

</div>

> 💁 **o1lab** _replied_

#### the idea of primary value is that it has to be humanly understandabale

#

---

<div class="post-metadata">

### Author: ![NocoDB](https://avatars.discourse-cdn.com/v4/letter/n/6f9a4e/32.png) [@NocoDB](https://community.nocodb.com/u/NocoDB)
#### Post date: [November 3, 2022, 8:58am UTC](https://community.nocodb.com/t/foreign-keys-as-primary-values-apr-19/370/4 "2022-11-03T08:58:48Z")

</div>

> 🙋‍♂️ **Harbard** _replied_

#### I understand your point. The thing is, I really need a relational DB for my use case, and I also need non-dev people to work on the DB. So nocoDB seems to be the perfect tool here !

#### Is my DB structure exotic ? Because I feel like it’s pretty commun. Let’s say I want to creat a new classroom and attach it to a school, the user will be faced with PK instead of the label.

 ![image0](https://canada1.discourse-cdn.com/flex011/uploads/nocodb/original/1X/bae520d33a7e104ccc5b33fef523df091e68ae91.png)

#

---

<div class="post-metadata">

### Author: ![NocoDB](https://avatars.discourse-cdn.com/v4/letter/n/6f9a4e/32.png) [@NocoDB](https://community.nocodb.com/u/NocoDB)
#### Post date: [November 3, 2022, 8:58am UTC](https://community.nocodb.com/t/foreign-keys-as-primary-values-apr-19/370/5 "2022-11-03T08:58:49Z")

</div>

> 🙋‍♂️ **Harbard** _replied_

#### Anyway, I’d be glad to discuss this topic with anyone in the team and try to help ! 🙏

#

---

<div class="post-metadata">

### Author: ![NocoDB](https://avatars.discourse-cdn.com/v4/letter/n/6f9a4e/32.png) [@NocoDB](https://community.nocodb.com/u/NocoDB)
#### Post date: [November 3, 2022, 8:58am UTC](https://community.nocodb.com/t/foreign-keys-as-primary-values-apr-19/370/6 "2022-11-03T08:58:50Z")

</div>

> 🙋‍♂️ **Harbard** _replied_

#### What is the best place to talk about this ? Here, an issue or GitHub discussions ?

#

---

<div class="post-metadata">

### Author: ![NocoDB](https://avatars.discourse-cdn.com/v4/letter/n/6f9a4e/32.png) [@NocoDB](https://community.nocodb.com/u/NocoDB)
#### Post date: [November 3, 2022, 8:58am UTC](https://community.nocodb.com/t/foreign-keys-as-primary-values-apr-19/370/7 "2022-11-03T08:58:51Z")

</div>

> 🙋‍♂️ **Harbard** _replied_

#### \<a:kbInklingWave:630956774727483422\> What do you guys think about that ?

#

---

<div class="post-metadata">

### Author: ![NocoDB](https://avatars.discourse-cdn.com/v4/letter/n/6f9a4e/32.png) [@NocoDB](https://community.nocodb.com/u/NocoDB)
#### Post date: [November 3, 2022, 8:58am UTC](https://community.nocodb.com/t/foreign-keys-as-primary-values-apr-19/370/8 "2022-11-03T08:58:53Z")

</div>

[Autogenerated from discord](https://discord.com/channels/661905455894888490/963488073566539796)

* * *

#### Join [NocoDB’s](http://www.nocodb.com/) community

[Discord](https://discord.gg/5RgZmkW) • [Twitter](https://twitter.com/nocodb) • [Reddit](https://www.reddit.com/r/NocoDB/) • [Docs](https://docs.nocodb.com/)
