Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

220
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!