作者:Utopia | 来源:互联网 | 2023-12-12 13:45
WhenIusepythontoapplythepymysqlmoduletoaddafieldtoatableinthemysqldatabase,itdo
When I use python to apply the pymysql module to add a field to a table in the mysql database,it does not return failure. However,when I query the database,I find that the new field is not displayed.
In addition,when I run the new field script again,it returns pymysql.err.InternalError: (1060,"Duplicate column name 'xxx xxx'")
以下是一个新的字段脚本
import pymysql
textdb = {
"host": "xx.xxx.xxx.xxx","database": "textdbs","user": "root","password": "xxxxxxxxx","port": 3306,"charset": 'utf8'
}
db = pymysql.connect(**textdb)
course = db.cursor()
sql = "alter table `{}` add `{}` varchar(255) default NULL".format("table","testund")
course.execute(sql)
这是应用于远程数据库的脚本。刚开始,我觉得脚本有问题。在本地数据库中进行实验后,我发现可以正常添加字段。
在course.commit()
之后添加course.executr(sql)