I have an Android project that includes a local database written in SQLite. There exists an sqldelight folder which contains a .sq file for every table in the database (User.sq, Routine.sq ...). I am able to access/use the tables and procedures defined here within my project.
Now, I intent to add Foreign Key relations to the database. However, if I try something like FOREIGN KEY (this_table_fk) REFERENCES OtherTable(other_table_pk)
, the project will not build because the .sq file I'm in is not able to find the OtherTable
table created from the CREATE TABLE
statement in OtherTable.sq or, by extension, its column other_table_pk
.
How can I allow the 2 different .sq files to "see" the tables generated by the other?
I tried putting the CREATE TABLE statements of ThisTable
and OtherTable
in the same .sq file, but I get mismatched input 'CREATE' expecting (<EOF>, IDENTIFIER, JAVADOC_COMMENT)
on the second CREATE TABLE statement. I'd much rather have a solution that keeps each table in its own .sq file, though.
Thanks.
Basic showing of ThisTable.sq
and OtherTable.sq
ThisTable.sq:
CREATE TABLE ThisTable (
this_table_pk INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
location TEXT,
start_date TEXT,
end_date TEXT,
this_column_fk INTEGER,
FOREIGN KEY (this_column_fk) REFERENCES OtherTable(other_column_pk)
);
OtherTable.sq:
CREATE TABLE OtherTable (
other_table_pk INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
location TEXT,
start_date TEXT,
end_date TEXT);