Creating foreign key constraints in ORMLite under SQLite

android, ormlite, sqlite

Solution

how to configure my database to enforce valid foreign keys, or perform cascaded deletes without explicit code overhead.

ORMLite supports a `columnDefinition="..."` field in the `@DatabaseFiled` annotation @Timo. I'm not sure if it provides you the power you need but it does allow you to have custom column definitions.

http://ormlite.com/javadoc/ormlite-core/com/j256/ormlite/field/DatabaseField.html#columnDefinition()

If it doesn't then I'm afraid that you may have to create your database outside of ORMLite in this case. You can use `TableUtils.getCreateTableStatements()` to get the statements necessary to create the table and add the enforcement and cascade statements that you need. Here are the javadocs for that method.

Problem

As it is not possible to add foreign keys using an "ALTER TABLE" statement in SQLite, I am stuck on how to configure my database to enforce valid foreign keys, or perform cascaded deletes without explicit code overhead. Anybody got an idea how to accomplish this with ORMLite under SQLite?

Original source

Related problems