def METHOD_NAME(FieldDependency, FormulaField, LinkRowField, Field):
    for link_row in LinkRowField.objects.filter(trashed=False).all():
        related_primary_field = link_row.link_row_table.field_set.filter(
            trashed=False
        ).get(primary=True)
        FieldDependency.objects.create(
            dependant=link_row, via=link_row, dependency=related_primary_field
        )
    for formula in FormulaField.objects.filter(trashed=False).all():
        tree = FormulaHandler.get_parse_tree_for_formula(formula.formula)
        dependency_field_names = tree.accept(BaserowFieldReferenceVisitor()) or set()
        table = formula.table
        for new_dependency_field_name in dependency_field_names:
            try:
                FieldDependency.objects.create(
                    dependency=table.field_set.filter(trashed=False).get(
                        name=new_dependency_field_name
                    ),
                    dependant=formula,
                )
            except Field.DoesNotExist:
                FieldDependency.objects.create(
                    dependant=formula,
                    broken_reference_field_name=new_dependency_field_name,
                )