2017-10-13 319 views
-1

在我的代碼的下面給定的行中執行代碼時,我正面臨操作錯誤。sqlite3.OperationalError:在「FOREIGN」附近:語法錯誤

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 

我無法看到的錯誤。

回答

0

此CREATE TABLE語句不定義任何列。 (FOREIGN KEY聲明對現有列的約束;它沒有定義新列)

而REFERENCES拼寫錯誤。

相關問題