0
    subscriber_package_forms = subscriber.package.form     
    # subscriber packages forms. 
    
    a = subscriber_package_forms.replace('[', '') 
    b = a.replace(']', '')
    c = b.replace("'", '')
    d = c.replace('''"''', '')
    e = d.replace("'", '')
    
    f = e.split(',')
    
    #search active columns of all the packages from main database.   
      
    for frm in f:
        
        frm = int(frm)
        try:
            form_columns_object = form_columns.objects.using(main_db).filter(form_id = frm).first()  
        except:
            pass
        
        if form_columns_object == None: 
            pass
        
        else:
            form_columns_dict = model_to_dict(form_columns_object)  
            form_instance = FormModel.objects.using(main_db).get(id = int(form_columns_dict['form']))
            user_instance = User.objects.using(main_db).first()   #get(username = form_columns_dict['user'])   #  id = form_columns_dict['id'] 
            form_columns.objects.using(db_name).create(columns = str(form_columns_dict['columns']), form = form_instance, user=user_instance)     
                 

This code is working fine in my local setup. But i am facing a problem after committing it on server.

We have error in last line of the code i guess

Abhishek
  • 9
  • 4
  • Did you apply ```migrations``` ? And could you add the error to the issue – iliya Sep 29 '22 at 11:32
  • I am working on existing project. and yes migrations are applied on my database tables – Abhishek Sep 29 '22 at 11:34
  • This error statement i am getting:-- 'Cannot add or update a child row: a foreign key constraint fails (`firsttest`.`form_columns`, CONSTRAINT `form_columns_form_id_9f19743a_fk_forms_id` FOREIGN KEY (`form_id`) REFERENCES `forms` (`id`))') – Abhishek Sep 29 '22 at 11:35
  • @ Did you also check this link: https://stackoverflow.com/questions/6178816/django-cannot-add-or-update-a-child-row-a-foreign-key-constraint-fails – iliya Sep 29 '22 at 11:40
  • I have just checked he is saying "Some of my tables were in InnoDB and some were in MyISAM... I changed everything to MyISAM and the problem was solved" But i cant put all my tables into a single database because i am dealing with 2 databases in this function. i have super admin having its own database and every subscriber having their own database – Abhishek Sep 29 '22 at 11:45

0 Answers0