-1

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

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

我看不到错误。

4

1 回答 1

0

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

并且 REFERENCES 拼写错误。

于 2017-10-13T19:39:12.510 回答