我有一台Mac,我正在尝试通过MAMP连接到myphpAdmin。我的表已创建。
#!/usr/local/bin/python3.7
import mysql.connector
from mysql.connector import errorcode
con = mysql.connector.connect(
user='root',
password='root',
host='localhost',
port= '8889',
database= 'Nov29',
)
print("It Works")
cursor = con.cursor()
addCon = ("INSERT INTO PhoneBook (ContactNo, ContactName,
ContactAddress) VALUES (%s,%s,%s)")
conNo = "4161313131"
conName = "Rin Okumura"
conAddress = "Cross Academy"
insertSql = (conNo,conName,conAddress)
cursor.execute(addCon,insertSql)
con.commit()
cursor.close()
con.close()
每当我尝试运行它时,我总是会得到这些错误。它一直引用我的python中的connection.py
文件。
这是我的错误:
It Works
File "/Users/atheyaramotar/PycharmProjects/Week12/connect.py", line 24, in <module>
cursor.execute(addCon,insertSql)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mysql/connector/cursor.py", line 569, in execute self._handle_result(self._connection.cmd_query(stmt))
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mysql/connector/connection.py", line 550, in cmd_query
result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mysql/connector/connection.py", line 439, in _handle_result
raise errors.get_exception(packet)
mysql.connector.errors.DataError: 1264 (22003): Out of range value for column 'ContactNo' at row 1
由于某种原因,我看到已经建立了通过终端的It Works
语句的连接,但是尚未对我的表进行任何更改。我在终端中尝试了nc -l 8889
命令,只是为了说它正在运行,并且没有错。如何运行程序并更改SQL数据库。