How to use drop_foreign_key_constraint method in autotest

Best Python code snippet using autotest_python Github


Full Screen

...43 local_cols=fk['constrained_columns'],44 remote_cols=fk['referred_columns'],45 ondelete=fk['options'].get('ondelete')46 )47def drop_foreign_key_constraint(table_name, fk_constraints):48 for fk in fk_constraints:49 op.drop_constraint(50 constraint_name=fk['name'],51 table_name=table_name,52 type_='foreignkey'53 )54@contextlib.contextmanager55def modify_foreign_keys_constraint(table_names):56 inspector = reflection.Inspector.from_engine(op.get_bind())57 try:58 for table in table_names:59 fk_constraints = inspector.get_foreign_keys(table)60 drop_foreign_key_constraint(table, fk_constraints)61 yield62 finally:63 for table in table_names:64 fk_constraints = inspector.get_foreign_keys(table)65 create_foreign_key_constraint(table, fk_constraints)66def modify_foreign_keys_constraint_with_col_change(67 table_name, old_local_col, new_local_col, existing_type,68 nullable=False):69 inspector = reflection.Inspector.from_engine(op.get_bind())70 fk_constraints = inspector.get_foreign_keys(table_name)71 for fk in fk_constraints:72 if old_local_col in fk['constrained_columns']:73 drop_foreign_key_constraint(table_name, [fk])74 op.alter_column(table_name, old_local_col,75 new_column_name=new_local_col,76 existing_type=existing_type,77 nullable=nullable)78 fk_constraints = inspector.get_foreign_keys(table_name)79 for fk in fk_constraints:80 for i in range(len(fk['constrained_columns'])):81 if old_local_col == fk['constrained_columns'][i]:82 fk['constrained_columns'][i] = new_local_col83 create_foreign_key_constraint(table_name, [fk])...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:


You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?