&引用;如何使用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)"""