2012-11-22 81 views
0

我想在onCreate()方法中創建一個表,但sqlite拋出異常,語法錯了。但如果我在Firefox SQLite管理器中嘗試相同的查詢,它創建表成功。不知道是什麼毛病我code.The查詢如下:創建表上的Android sqlite異常

CREATE TABLE playlistSongs(
id INTEGER PRIMARY KEY, 
playlist_id INTEGER, 
FOREIGN KEY(playlist_id) REFERENCES playlists(id) ON DELETE CASCADE, 
song_id INTEGER, 
FOREIGN KEY(song_id) REFERENCES songs(id) ON DELETE CASCADE); 

的例外是:

11-22 16:44:58.066: E/AndroidRuntime(11241): Caused by: 
android.database.sqlite.SQLiteException: near "song_id": syntax error: 
CREATE TABLE playlistSongs(id INTEGER PRIMARY KEY,playlist_id 
INTEGER,FOREIGN KEY(playlist_id) REFERENCES playlists(id) ON DELETE 
CASCADE,song_id INTEGER,FOREIGN KEY(song_id) REFERENCES songs(id) ON 
DELETE CASCADE); 
+0

什麼'PRAGMA compile_options的結果;'在兩個數據庫? –

+0

什麼是PRAGMA compile_options; ?我真的不知道這個以及如何使用它? – Anshul

+0

我認爲你應該在最後申報外鍵 – njzk2

回答

0

問題是外國KEY declaration.I曾在類似這樣的結尾聲明它們:

CREATE TABLE playlistSongs(ID INTEGER PRIMARY KEY,PLAYLIST_ID INTEGER,song_id INTEGER,外鍵(PLAYLIST_ID)參考文獻 播放列表(ID)ON DELETE CASCADE,外鍵(song_id)參考文獻 歌曲(ID)ON DELETE級聯);

感謝@ njzk2