Reputation: 17753
I am trying to create table with Foreign Key, but Netbeans is giving me SQLite exepction - syntax error:
AndroidRuntime Caused by: android.database.sqlite.SQLiteException: near "_id": syntax error: CREATE TABLE customer1 _id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, info REAL, customer_a INTEGER, FOREIGN KEY (customer_a) REFERENCES customer4 (_id);
Whilst, table customer4 in time of creating table customer1 exists, I am still getting syntax error. I have been looking on the web and I haven't found anything stating, I have bad syntax. Do you see where is the problem?
Thanks
Upvotes: 0
Views: 270
Reputation: 1632
Which android version do you use? Foreign keys are only available since Android 2.2. Source
Upvotes: 0
Reputation: 30825
You're missing parenthesis around your column names. You need to do something like this:
CREATE TABLE customer1 (_id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT, info REAL, customer_a INTEGER REFERENCES customer4(_id));
Upvotes: 1