title: How to achieve an "Inheritance" relationship in SQLite database on Android
body: <p>Consider this simple model:</p>
  
  <p>A base Location table:</p>
  
  <pre><code>+-------------------------------+
  |           Locations           |
  +-------------------------------+
  |(PK) _id Integer Autoincrement |
  |     name Text(100) Not null   |
  |     is_in_range Integer       |
  +-------------------------------+
  </code></pre>
  
  <p>And more specialized table called WifiLocation:</p>
  
  <pre><code>+-------------------------------+
  |         wifi_location         |
  +-------------------------------+
  |     ssid Text(0) Not null     |
  |     signal_threshold Real     |
  |(PK) _id Integer               |
  +-------------------------------+
  </code></pre>
  
  <p>I want that this model will represents a <code>WifiLocation</code> inheriting from <code>BaseLocation</code>.
  So I added a <code>REFERENCES</code> clause on the <code>_id</code> column of the <code>wifi_locations</code> table like that:</p>
  
  <pre><code>CREATE TABLE wifi_locations (_id Integer primary key references Locations(_id), ....)
  </code></pre>
  
  <p>I'm trying to achieve a 1:1 relationship between those tables.</p>
  
  <p>When I want to insert a row to the <code>wifi_locations</code> table, I first insert the appropriate values (Name, IsInRange) to the <code>Locations</code> table, and get back the <code>rowId</code>.
  Then I insert the rest of the data (ssid) to the <code>wifi_locations</code> table along with the rowId as the foreign key.</p>
  
  <p>So the insertion to the Location table is working, and I'm getting back an Id, but when I try to use this Id and insert it to the wifi_locations table, I'm getting an SQL <code>Constraint violation</code> error. There are no more details about what exactly went wrong.</p>
  
  <p>Is there anything wrong with my schema? Is there a better way to achieve such modeling?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>The exact error:</p>
  
  <pre><code>06-16 15:56:42.846: E/Database(2038):
  android.database.sqlite.SQLiteConstraintException: 
  error code 19: constraint failed
  </code></pre>