Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

221
Vistas
Trigger to send new rows added to database to another database in postgres?

I have 2 databases on 2 different servers (say A & B).
I have some crawlers that use API functions to write data to database (A). Some of this data are new and others are just updates to previous rows. If some new rows are added to (A) I want to add id of these new rows to (B).


I want this to happen in real time without full scan of (A) iteratively. I want something like a trigger in (A) to send new ids to (B). How should I do write this trigger?(If you think there is a better solution, please help me)

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

you can do it by using django signals. Signals means just like trigger. if you want do any operation while creating updating deleting models. you can use signals. django reference reference example

suppose you have two models named:

class A(models.Model):
  name = models.CharField(max_length=128)

class B(models.Model):
  a = models.ForeignKey(A)

save this file in your app/signals.py

from django.db.models.signals import post_save
from .models import A,B

def create_b(sender, instance, created, *args, **kwargs):

    if created:
       B.objects.create(a=instance)

post_save.connect(create_b, sender=A)

and inorder to work this signals properly you have to call it in apps config. and in app.py file copy this

class ProductConfig(AppConfig): #this will be different
    name = 'product' # this will be different based on your app name
#copy below lines only
    def ready(self):
        from .signals import *

and in your app's __init__.py file include this line

default_app_config = "product.apps.ProductConfig"
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda