Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
&引用;如何使用CREATE方法修复python IDE中sql中已经存在的错误表;_Python_Sql_Python 3.x - Fatal编程技术网

&引用;如何使用CREATE方法修复python IDE中sql中已经存在的错误表;

&引用;如何使用CREATE方法修复python IDE中sql中已经存在的错误表;,python,sql,python-3.x,Python,Sql,Python 3.x,当我使用Pycharm时,错误不断弹出: Traceback (most recent call last): File "C:/Users/aaa/.PyCharmCE2019.2/config/scratches/sql_class.py", line 11, in <module> cur.execute(customers_sql) sqlite3.OperationalError: table customers already exists 预期的输出是打印

当我使用
Pycharm
时,错误不断弹出:

Traceback (most recent call last):
  File "C:/Users/aaa/.PyCharmCE2019.2/config/scratches/sql_class.py", line 11, in <module>
    cur.execute(customers_sql)
sqlite3.OperationalError: table customers already exists

预期的输出是打印出表。

您正在尝试创建一个已经存在的表,这在Sqlite中是不可能的

要解决这个问题,可以在查询中使用该语句

因此,您的代码块将是:

customers_sql = """
      CREATE TABLE IF NOT EXISTS customers (
      id integer PRIMARY KEY,
      first_name text NOT NULL,
      last_name text NOT NULL)"""

有人告诉我,长sql代码不能与pycharm一起使用
customers_sql = """
      CREATE TABLE IF NOT EXISTS customers (
      id integer PRIMARY KEY,
      first_name text NOT NULL,
      last_name text NOT NULL)"""