1

Is this supported? I'm attempting to create a table but am getting a syntax error when compiling.

private static final String ROOM_CREATE =
        "create table room (_id integer primary key autoincrement, " +
        "facility integer not null, FORIEGN KEY (facility) REFERENCES facility(_id));";
David Snabel-Caunt
  • 57,156
  • 12
  • 110
  • 132
bgrantdev
  • 1,542
  • 4
  • 15
  • 29
  • possible duplicate of [Foreign key constraints in Android using SQLite? on Delete cascade](http://stackoverflow.com/questions/2545558/foreign-key-constraints-in-android-using-sqlite-on-delete-cascade) – Ted Hopp Jan 12 '12 at 19:34
  • It is possible. Syntax error from compiling could be different one, can you post the error you are getting? – kosa Jan 12 '12 at 19:37
  • FORIEGN KEY...syntax error – Mirko Jul 30 '13 at 10:44

4 Answers4

0

You can create foreign keys, but you have to enable enforcement in SQLite with

PRAGMA foreign_keys = ON;
ᅙᄉᅙ
  • 17,132
  • 10
  • 64
  • 97
0

Typo in the SQL:

FORIEGN -> FOREIGN

sebastianf182
  • 9,518
  • 3
  • 30
  • 62
0

Some great answers, particularly @sfratini for spotting the typo in the FOREIGN keyword. Can I also recommend that you should troubleshoot your SQL statements by using a command line client, such as the "Precompiled Binaries For Windows" (see http://sqlite.org/download.html). That way, you can validate the CREATE TABLE and INSERT statements before you put them into your app.

Stephen Quan
  • 16,666
  • 3
  • 73
  • 69
-1

The facility in facility(_id) must refers to table name. You are defining same name to column also. Please change table name and try again.

GrAnd
  • 10,051
  • 3
  • 29
  • 41
Ramesh 586
  • 67
  • 3