0

I am making a KMM app using SQLDelight for the cache and recently I changed my database entities to use Text(String) for the id field instead of Int, now i am getting an error when inserting, I might just be missing some sqlDelight knowledge

here is my table:

 CREATE TABLE sidework_Entity(
   id TEXT NOT NULL PRIMARY KEY,
   name TEXT NOT NULL,
   employees TEXT NOT NULL,
   todoToday INTEGER AS Boolean DEFAULT 0
);

here is my insert method:

insertSidework:
INSERT OR REPLACE
INTO sidework_Entity(
       id,
       name,
       employees,
       todoToday
) VALUES (?,?,?,?);

here is my error:

statement aborts at 5: [INSERT OR REPLACE
    INTO sidework_Entity(
           id,
           name,
           employees,
           todoToday
    ) VALUES (?,?,?,?)] datatype mismatch

I think it is most likely the Primary Key i have set on the id field or something of that sort but the documentation is a bit short.

Ken White
  • 123,280
  • 14
  • 225
  • 444
barryalan2633
  • 610
  • 7
  • 21
  • 1
    turns out i just needed to clean app and delete the old app from my device before re running, most likely the old db table where I had the id as int was still lurking in there somewhere. thanks anyways guys – barryalan2633 Oct 23 '21 at 03:16
  • check out [how](https://cashapp.github.io/sqldelight/jvm_sqlite/migrations/) you can run migration, in case you don't wanna ask user to reinstall the app when your DB is changed – Phil Dukhov Oct 28 '21 at 10:42

1 Answers1

0

The solution to this problem is actually running a migration. Although deleting the app to clear the database cache is a valid solution for testing purposes. For an app in production, this isn't the correct approach.

Documentation for running Migration

Stackoverflow answer with explanation

Narendra_Nath
  • 4,578
  • 3
  • 13
  • 31