I'm trying to create a discord bot with python and need a database Table for listing member warnings. but when I'm trying to make a table in the database I get this error:
Traceback (most recent call last):
File "D:\.Python\moalmeme-test-bot\db.py", line 21, in <module>
setup()
File "D:\.Python\moalmeme-test-bot\db.py", line 18, in setup
cur.execute("CREATE TABLE IF NOT EXISTS `warns` (warn_id INT AUTO_INCREMENT PRIMARY KEY, discord_member_id VARCHAR, discord_server_id VARCHAR, reason VARCHAR);")
File "D:\.Python\moalmeme-test-bot\venv\lib\site-packages\mariadb\cursors.py", line 307, in execute
self._readresponse()
mariadb.ProgrammingError: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'discord_server_id VARCHAR, reason VARCHAR)' at line 1
this is my code:
import mariadb
import sys
connection = mariadb.connect(
user=os.getenv("DB_USER"),
password=os.getenv("DB_PASSWORD"),
host=os.getenv("DB_HOST"),
port=os.getenv("DB_PORT"),
database=os.getenv("DB_NAME")
)
cur = connection.cursor()
def setup():
cur.execute("CREATE TABLE IF NOT EXISTS `warns` (warn_id INT AUTO_INCREMENT PRIMARY KEY, discord_member_id VARCHAR, discord_server_id VARCHAR, reason VARCHAR);")
setup()
python version: 3.10 mariaDB server version: 10.5 mariaDB python package version: 1.1.4
CodePudding user response:
your column varchar datatype don't have the lengths.
CREATE TABLE IF NOT EXISTS `warns` (warn_id INT AUTO_INCREMENT PRIMARY KEY, discord_member_id VARCHAR(3), discord_server_id VARCHAR(3), reason VARCHAR(100));