我正在尝试在onCreate()方法中创建一个表,但sqlite抛出异常,语法错误。但是如果我在Firefox SQLite Manager中尝试相同的查询它成功创建表。我不知道我的问题是什么code。查询如下:
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 :(得分:0)
问题是FOREIGN KEY声明。我最后声明了它们:
CREATE TABLE播放列表歌曲(id INTEGER PRIMARY KEY,playlist_id INTEGER,song_id INTEGER,FOREIGN KEY(playlist_id)参考 播放列表(id)ON DELETE CASCADE,FOREIGN KEY(song_id)REFERENCES 歌曲(id)ON DELETE CASCADE);
感谢@ njzk2