python - 我的 python 代码在创建模式和更新外键时跳过 SQL 语句,请建议
问题描述
我对 python 还很陌生,我编写了一个 python 代码,它使用 mysql.connector 包执行 Mysql 脚本以“创建表模式并添加外键”。我正在为多个表运行此脚本,一次使用 3 个 sql 语句。该代码在本地计算机上运行时执行良好,但在 ISPAN 中运行时缺少创建一些表和更新外键,尽管执行成功。
以下是我创建的示例脚本:
use prime; create table Address(
Address_Uniq_Identifier varchar(25) Not Null
,Address_Locat_Name varchar(50) Not Null
,Address_Line_1 varchar(100) Not Null
,Address_Line_2 varchar(100) Default Null
,Source_Reference varchar(25) Default Null
,Primary Key (Address_Uniq_Identifier));
use prime; create table People(
People_Uniq_Identifier varchar(25) Not Null
,Legal_Entity int(1) Not Null
,Title varchar(20) Default Null
,Last_Name varchar(30) Not Null
,Source_Reference varchar(25) Default Null
,Primary Key (People_Uniq_Identifier));
use prime; create table Account(
Account_Uniq_Identifier varchar(25) Not Null
,Customer_Uniqu_Identifier varchar(25) Not Null
,Primary_Acco_Uni_Identifier varchar(25) Not Null
,Financial_Statu_Code varchar(4) Default Null
,Authorization_Statu_Code varchar(4) Default Null
,Source_Reference varchar(25) Default Null
,Primary Key (Account_Uniq_Identifier));
use prime; create table Customer(
Customer_Uniq_Identifier varchar(25) Not Null
,People_Uniqu_Identifier varchar(25) Not Null
,Customer_Type int(5) Not Null
,Source_Reference varchar(25) Default Null
,Primary Key (Customer_Uniq_Identifier));
use prime; Alter table Customer
ADD FOREIGN KEY (People_Uniqu_Identifier) REFERENCES People (People_Uniq_Identifier);
以下是代码片段:
//Reading file
//Making SQL connectivity
mydb = mysql.connector.connect(
host="**7.*.*.1",
user="r**t",
password="N***a@*0*1",
database="prime"
)
mycursor = mydb.cursor()
//Creating script
//Executing script 3 at a time using the following code in loop
mycursor.execute(record_exe) //*executing the first 3 sql stmt
mycursor.fetchall()
mycursor.close() //* closing sql cursor
mydb.close() //* closing database connectivity
record_exe = "" //* initialising the sql statement with spaces
count_semi =0
mydb = mysql.connector.connect(
host="**7.*.*.1", //* creating the connectivity again
user="r**t",
password="N***a@*0*1",
database="prime"
)
mycursor = mydb.cursor() //* creating a new cursor
time.sleep(5) //* added sleep time to counter for lag on ISPAN
当我在 ISPAN 上运行这段代码时,问题就出现了,虽然它执行得很好,但有些表丢失了,外键更新没有完成。请帮助建议一种方法来检查它为什么会跳过一些 sql 命令
解决方案
推荐阅读
- android - 在不设置 windowIsTranslucent 的情况下在锁屏上创建透明活动
- ruby-on-rails - 跳过对依赖项的验证::destroy
- google-apps-script - Error Showing in Simple Google Apps Script, How to hide
- javascript - Vue.js 组件在 jsp 文件中不起作用
- javascript - node.js JS 堆内存不足错误 - 无论 max-old-space-size 设置如何
- c++ - 将多个函数传递给模板
- c# - 打开串口时 USB 相机崩溃
- java - 错误:java.lang.NumberFormatException:对于输入字符串:“时间”
- wordpress - 更改 WordPress 导航菜单中的默认 html 结构
- spring-boot - 使用 java.lang.NullPointerException 进行 Mockito 测试