'sqlite3.OperationalError: near ")": syntax error' while creating a table
'sqlite3.OperationalError: near ")": syntax error' while creating a table
我正在尝试为我的社区制作一个股票程序,并且我正在尝试 运行 此代码:
def create_tables():
c.execute('CREATE TABLE IF NOT EXISTS products(cod INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, bar_code INTEGER, '\
'descr VARCHAR(100) NOT NULL, quant_stock REAL, type_un TEXT, cost_un REAL, value_un REAL NOT NULL, fab_date TEXT, '\
'due_date TEXT)')
c.execute('CREATE TABLE IF NOT EXISTS sells(cod INTEGER NOT NULL, bar_code INTEGER, '\
'descr TEXT PRIMARY KEY NOT NULL, value_un REAL NOT NULL, type_un TEXT, quant_stock REAL NOT NULL, '\
'tot_value REAL NOT NULL, sell_date TEXT NOT NULL, FOREIGN KEY (cod) REFERENCES products(cod)')
c.execute('CREATE TABLE IF NOT EXISTS purchase(cod INTEGER FOREIGN KEY, bar_code INTEGER, '\
'descr TEXT NOT NULL, cost_un REAL, type_un TEXT, pur_quant REAL NOT NULL, tot_cost REAL NOT NULL, '\
'pur_date TEXT NOT NULL, fab_date TEXT, due_date TEXT')
我得到这个错误:
File "app.py", line 17, in create_tables
c.execute('CREATE TABLE IF NOT EXISTS sells(cod INTEGER NOT NULL, bar_code INTEGER, '\
sqlite3.OperationalError: near ")": syntax error
我不知道为什么会这样,因为创建第一个 table 没有问题(我已经正常评论了另外两个和脚本 运行)。有人可以帮我吗?
您在第二个和第三个 table 插入中缺少右括号:
def create_tables():
c.execute('CREATE TABLE IF NOT EXISTS products(cod INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, bar_code INTEGER, '\
'descr VARCHAR(100) NOT NULL, quant_stock REAL, type_un TEXT, cost_un REAL, value_un REAL NOT NULL, fab_date TEXT, '\
'due_date TEXT)')
c.execute('CREATE TABLE IF NOT EXISTS sells(cod INTEGER NOT NULL, bar_code INTEGER, '\
'descr TEXT PRIMARY KEY NOT NULL, value_un REAL NOT NULL, type_un TEXT, quant_stock REAL NOT NULL, '\
'tot_value REAL NOT NULL, sell_date TEXT NOT NULL, FOREIGN KEY (cod) REFERENCES products(cod))')
c.execute('CREATE TABLE IF NOT EXISTS purchase(cod INTEGER FOREIGN KEY, bar_code INTEGER, '\
'descr TEXT NOT NULL, cost_un REAL, type_un TEXT, pur_quant REAL NOT NULL, tot_cost REAL NOT NULL, '\
'pur_date TEXT NOT NULL, fab_date TEXT, due_date TEXT)')
我正在尝试为我的社区制作一个股票程序,并且我正在尝试 运行 此代码:
def create_tables():
c.execute('CREATE TABLE IF NOT EXISTS products(cod INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, bar_code INTEGER, '\
'descr VARCHAR(100) NOT NULL, quant_stock REAL, type_un TEXT, cost_un REAL, value_un REAL NOT NULL, fab_date TEXT, '\
'due_date TEXT)')
c.execute('CREATE TABLE IF NOT EXISTS sells(cod INTEGER NOT NULL, bar_code INTEGER, '\
'descr TEXT PRIMARY KEY NOT NULL, value_un REAL NOT NULL, type_un TEXT, quant_stock REAL NOT NULL, '\
'tot_value REAL NOT NULL, sell_date TEXT NOT NULL, FOREIGN KEY (cod) REFERENCES products(cod)')
c.execute('CREATE TABLE IF NOT EXISTS purchase(cod INTEGER FOREIGN KEY, bar_code INTEGER, '\
'descr TEXT NOT NULL, cost_un REAL, type_un TEXT, pur_quant REAL NOT NULL, tot_cost REAL NOT NULL, '\
'pur_date TEXT NOT NULL, fab_date TEXT, due_date TEXT')
我得到这个错误:
File "app.py", line 17, in create_tables
c.execute('CREATE TABLE IF NOT EXISTS sells(cod INTEGER NOT NULL, bar_code INTEGER, '\
sqlite3.OperationalError: near ")": syntax error
我不知道为什么会这样,因为创建第一个 table 没有问题(我已经正常评论了另外两个和脚本 运行)。有人可以帮我吗?
您在第二个和第三个 table 插入中缺少右括号:
def create_tables():
c.execute('CREATE TABLE IF NOT EXISTS products(cod INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, bar_code INTEGER, '\
'descr VARCHAR(100) NOT NULL, quant_stock REAL, type_un TEXT, cost_un REAL, value_un REAL NOT NULL, fab_date TEXT, '\
'due_date TEXT)')
c.execute('CREATE TABLE IF NOT EXISTS sells(cod INTEGER NOT NULL, bar_code INTEGER, '\
'descr TEXT PRIMARY KEY NOT NULL, value_un REAL NOT NULL, type_un TEXT, quant_stock REAL NOT NULL, '\
'tot_value REAL NOT NULL, sell_date TEXT NOT NULL, FOREIGN KEY (cod) REFERENCES products(cod))')
c.execute('CREATE TABLE IF NOT EXISTS purchase(cod INTEGER FOREIGN KEY, bar_code INTEGER, '\
'descr TEXT NOT NULL, cost_un REAL, type_un TEXT, pur_quant REAL NOT NULL, tot_cost REAL NOT NULL, '\
'pur_date TEXT NOT NULL, fab_date TEXT, due_date TEXT)')