Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

165
Visualizações
How to update primary key and it's references to other tables at the same time

I have a main table with primary key as 'main_id'. This 'main_id' is being used a foreign key in two tables : 'sub_table1', 'sub_table2'

I have a requirement where I need to change the 'main_id' and it's references in 'sub_table1' and 'sub_table2'.

I am on Nodejs and using Bookshelf and Knex.

So far I tried updating the sub_tables first and then tried updating the main_table. But it threw error 'Foreign_key constraint being violated'.

I'm new at using Bookshelf. Please help

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Foreign keys are absolutely constant and this might not be what you actually want to do. I mean, there is no real reason why you would like to change the id as it's an identification for you as a developer to work with, not something that should be able to be overwritten. If for some reason you need the user to have something similar to an identification that they can overwrite, you can simply create a new column called for example 'code' or 'customId' (or whatever, you got the point) and make it unique.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda