Why do i get error 1064 (42000) near : avatar VARCHAR(1028) DEFAULT `image.jpeg`,

huangapple go评论64阅读模式
英文:

Why do i get error 1064 (42000) near : avatar VARCHAR(1028) DEFAULT `image.jpeg`,

问题

以下是您的脚本的翻译部分:

这是我的用于连接到mysql的脚本

我尝试创建一个连接器或中间件用于连接mysql数据库和flask应用程序

当我尝试创建一个表时我遇到了一个错误

import mysql.connector
from mysql.connector import Error as SQLError

db_info = ['localhost', 'xxx', 'xxx', 'xxx']

# 尝试连接到服务器

try:
    connection = mysql.connector.connect(host=db_info[0],
                                         database=db_info[1],
                                         user=db_info[2],
                                         password=db_info[3])

    if connection.is_connected():
        db_Info = connection.get_server_info()
        print("Connected to MySQL Server version ", db_Info)
        cursor = connection.cursor() # 游标
        cursor.execute("select database();")
        record = cursor.fetchone()
        print("You're connected to database: ", record)

except SQLError as e:
    print("Error while connecting to MySQL", e)
    quit()

artist_table_create = """
CREATE TABLE artist (
    id INT NOT NULL,
    sid INT NOT NULL,
    name VARCHAR(32) NOT NULL,
    birthdate DATE NOT NULL,
    gender ENUM('0', '1') NOT NULL,
    code_melli VARCHAR(32) NOT NULL,
    phonenumber VARCHAR(16) NOT NULL,
    email VARCHAR(128) NOT NULL,
    location1 VARCHAR(32) NOT NULL,
    location2 VARCHAR(32) NOT NULL, 
    date_signedup DATE NOT NULL,
    verification_status ENUM('0', '1'),
    avatar VARCHAR(1028) DEFAULT 'image.jpeg',
    rank VARCHAR(256) NOT NULL,
    env1 VARCHAR(256) NOT NULL, 
    env2 VARCHAR(256) NOT NULL,
    env3 VARCHAR(256) NOT NULL,
    PRIMARY KEY (id, sid, phonenumber)
);
"""

try:
    result = cursor.execute(artist_table_create)
except SQLError as e:
    print(e)

这是命令行中的错误翻译:

1064 (42000): 您的SQL语法有误; 请查看与您的MySQL服务器版本相对应的手册,以了解在第14行使用正确语法

我不知道我应该怎样理解MySQL的错误。我需要修复这个错误。

英文:

This is my script for connecting to mysql

im trying to create a connector or middle man for mysql database and flask application

while im tyring to create a table i hit an error


#!/usr/bin/python


import mysql.connector
from mysql.connector import Error as SQLError

db_info = ['localhost', 'xxx', 'xxx', 'xxx']

# Trying to connect to server

try:
    connection = mysql.connector.connect(host=db_info[0],
                                         database=db_info[1],
                                         user=db_info[2],
                                         password=db_info[3])

    if connection.is_connected():
        db_Info = connection.get_server_info()
        print("Connected to MySQL Server version ", db_Info)
        cursor = connection.cursor() # CURSOR
        cursor.execute("select database();")
        record = cursor.fetchone()
        print("You're connected to database: ", record)

except SQLError as e:
    print("Error while connecting to MySQL", e)
    quit()


artist_table_create = """
CREATE TABLE artist (
    id INT NOT NULL,
    sid INT NOT NULL,
    name VARCHAR(32) NOT NULL,
    birthdate DATE NOT NULL,
    gender ENUM('0', '1') NOT NULL,
    code_melli VARCHAR(32) NOT NULL,
    phonenumber VARCHAR(16) NOT NULL,
    email VARCHAR(128) NOT NULL,
    location1 VARCHAR(32) NOT NULL,
    location2 VARCHAR(32) NOT NULL, 
    date_signedup DATE NOT NULL,
    verification_status ENUM('0', '1'),
    avatar VARCHAR(1028) DEFAULT `image.jpeg`,
    rank VARCHAR(256) NOT NULL,
    env1 VARCHAR(256) NOT NULL, 
    env2 VARCHAR(256) NOT NULL,
    env3 VARCHAR(256) NOT NULL,
    PRIMARY KEY (id, sid, phonenumber)
);"""

try:
    result = cursor.execute(artist_table_create)
except SQLError as e:
    print(e)

And this is my error in command line:

1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`image.jpeg`,
    rank VARCHAR(256) NOT NULL,
    env1 VARCHAR(256) NOT NULL, 
 ' at line 14

I dont know what should i cant understand mysql errors

I need to fix this error

答案1

得分: 2

MySQL错误已经很好地指示了问题可能出现的位置。它实际上说错误出现在 `image.jpeg` 附近。正如你所看到的,你正在使用 ` 的反引号,它们看起来像这样:` `。但你必须使用普通的单引号,它们是这样的:' '。为了修复你的错误,你只需在 image.jpeg 周围加上单引号即可。

英文:

The MySQL errror is already a pretty good indicator where the problem might be. It actually says the error is near `image.jpeg`. As you can see you are using backqoutes which look are these: ` `. But you have to use normal sinqle quotes, which are these: ' '. In order to fix your error you simple have to put single qoutes around image.jpeg instead of the backqoutes.

huangapple
  • 本文由 发表于 2023年1月8日 22:55:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/75048748.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定