0

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

Waypoint
  • 17,283
  • 39
  • 116
  • 170

2 Answers2

1

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));
Kurtis Nusbaum
  • 30,445
  • 13
  • 78
  • 102
  • Thanks so, I should have added brackets and I should have merged both "customer_a INTEGER" and "FOREIGN KEY (customer_a) REFERENCES customer4(_id)" into "customer_a INTEGER REFERENCES customer4(_id)"? – Waypoint Nov 04 '11 at 15:04
0

Which android version do you use? Foreign keys are only available since Android 2.2. Source

Community
  • 1
  • 1
js-
  • 1,632
  • 1
  • 14
  • 18