I’m trying to add a foreign key through migration ...
# squarelibraries
l
I’m trying to add a foreign key through migration for my SqlDelight table as follows,
0.sqm
Copy code
CREATE TABLE IF NOT EXISTS entry(
    ...
);
1.sqm
Copy code
PRAGMA foreign_keys=off;
BEGIN TRANSACTION;
CREATE TABLE IF NOT EXISTS entry_temp(
    ...
    key INTEGER,
    FOREIGN KEY(key) REFERENCES ...
);
INSERT INTO entry_temp (...) SELECT * FROM entry;

DROP TABLE entry;
ALTER TABLE entry_temp RENAME TO entry;
COMMIT;
PRAGMA foreign_keys=on;
But upon running
generateCommonMainDBInterface
task I get an error for with the following stacktrace.
Copy code
> A failure occurred while executing com.squareup.sqldelight.gradle.SqlDelightTask$GenerateInterfaces
   > Failed to compile SqlInsertStmtImpl(INSERT_STMT): [] :
     INSERT INTO entry(...)
     VALUES (?, ?, ?, ...)

java.lang.IllegalStateException: Cannot get reference table for psi type class sqldelight.com.alecstrong.sql.psi.core.psi.impl.SqlNewTableNameImpl
This
INSERT
statement is written in the
.sq
file and is syntactically correct. However if I don’t rename the table and use
entry_temp
as it is (with necessary changes in
.sq
file as well), the task runs successfully. Am I missing something here? blob thinking fast