sqlite3.OperationalError:near" FOREIGN":语法错误

时间:2017-10-13 18:07:45

标签: sqlite python-3.4 operationalerror

在我的代码的以下给定行执行代码时,我遇到操作错误。

c.execute("CREATE TABLE IF NOT EXISTS customerReg(cname TEXT,cgender TEXT,cphone INT UNIQUE,cusername TEXT UNIQUE,cpassword TEXT UNIQUE)")
    c.execute("CREATE TABLE IF NOT EXISTS adminReg(Oname TEXT,Hname TEXT UNIQUE,totalrooms INT,tariff INT,location TEXT,aphone INT,ausername TEXT UNIQUE,apassword TEXT UNIQUE)")
    c.execute("CREATE TABLE IF NOT EXISTS customerStay(cname TEXT,hostel TEXT,location TEXT,tariff INT)")
    c.execute("CREATE TABLE IF NOT EXISTS Hostel(FOREIGN KEY(Hostelname) REFERENCE adminReg(Hname),FOREIGN KEY(rent) REFERENCE adminReg(tariff),FOREIGN KEY(roomsavailable) REFERENCE adminReg(totalrooms))")

正在显示的错误是

 c.execute("CREATE TABLE IF NOT EXISTS Hostel(FOREIGN KEY(Hostelname)
 REFERENCE adminReg(Hname),FOREIGN KEY(rent) REFERENCE
 adminReg(tariff),FOREIGN KEY(roomsavailable) REFERENCE
 adminReg(totalrooms))") sqlite3.OperationalError: near "FOREIGN":
 syntax error

我无法看到错误。

1 个答案:

答案 0 :(得分:0)

此CREATE TABLE语句未定义任何列。 (FOREIGN KEY在现有列上声明约束;它不定义新列。)

参考拼写错误。