jepiqueau / vue-typeorm-app

Vue App using TypeORM driver with @capacitor-community/sqlite
MIT License
10 stars 3 forks source link

@PrimaryGeneratedColumn Not Working #8

Closed vycoder closed 1 year ago

vycoder commented 1 year ago

I had everything setup nicely. But I have my schema on local JSON. I'm importing it via importFromJSON()

Problem is, when i save an entity. It errors out with:

22:56:40.514 Capacitor/Console       org.myapp.app E  File: webpack-internal:///./node_modules/typeorm/browser/platform/BrowserPlatformTools.js - Line 114 - Msg: query failed:  INSERT INTO "favorites"("id", "target_id", "type", "last_modified") VALUES (NULL, 81, ?, NULL) -- PARAMETERS: ["type"]

Even though my entity has @PrimaryGeneratedColumn on it. The only thing that seem to work is when I use @PrimaryGeneratedColumn('uuid'), the supplied value is no longer NULL but indeed a generated uuid. Unfortunately though, I'm also having trouble with this, sometimes it errors out as well with code error 20, I think it was because SQLite does not seem to accept a primary key of TEXT. Was able to confirm that bit, when I manually set favorites.id into any number. It works alright that way.

But isn't the point of @PrimaryGeneratedColumn so that I don't have to generate it myself?

I even tried doing:

But nothing's working. Do I really have to manually generate an id?

vycoder commented 1 year ago

My bad. Closing this issue. SQLite does accept TEXT as primary key it seems. My issue is just my own stupidity, i was editing a duplicate my schema, the schema json that wasn't the actual file being imported. That' why I keep getting weird errors. It was only on that table that's failing, my original implementation was correct. I need to sleep

jepiqueau commented 1 year ago

@vycoder 👍