0

我正在尝试在 onCreate() 方法中创建一个表,但 sqlite 抛出语法错误的异常。但是如果我在 Firefox SQLite Manager 中尝试相同的查询,它会成功创建表。我不知道我的代码有什么问题。查询如下:

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);
4

1 回答 1

0

问题是外键声明。我在最后声明它们是这样的:

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

感谢@njzk2

于 2012-11-22T13:35:06.760 回答