Scheduled Job gets deleted on migrating code

I have created scheduled task on saving doctype. But when I migrate code then scheduled task from Scheduled Job Type doctype gets deleted/removed. So how to restrict that deleting ?
I am using frappe version 13.

bench --site Test migrate

def message():
	print("Completed Schedule Task.")

def on_submit(docname,time):
	# Calculate the delay in seconds between now and the schedule_date_time
	schedule_time = datetime.strptime(time, '%Y-%m-%d %H:%M:%S')
	one_day_earlier = schedule_time - timedelta(days=1)
	hours = one_day_earlier.hour
	minutes = one_day_earlier.minute
	now = now_datetime()
	delay = (schedule_time - now).total_seconds()
	if delay > 0:
		if "IM-" in docname:	
			print("IM", docname)
			if frappe.db.exists("Scheduled Job Type", docname):
				job_doc = frappe.get_doc("Scheduled Job Type", docname)
				job_doc.method = "test.test.doctype.messanger.messanger.message"
				job_doc.frequency = "Cron"  # You can set other frequencies as desired
				job_doc.cron_format = f"{minutes} {hours} * * * *"
				job_doc.last_execution = one_day_earlier
				job_doc.queue = "Daily"  # Specify the queue