Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: drizzle-kit push:sqlite - Foriegn keys referencing __old_push_[table name] after #369

Open
CamTheGoblin opened this issue Apr 21, 2024 · 2 comments

Comments

@CamTheGoblin
Copy link

The Issue:

After making a change to the schema, and running drizzle-kit push:sqlite, Requests made from my application started getting the following error:

 ⨯ Internal error: SqliteError: no such table: main.__old_push_[table name]
    at Database.prepare ([path to project]\node_modules\.pnpm\better-sqlite3@9.5.0\node_modules\better-sqlite3\lib\methods\wrappers.js:5:21)
    at BetterSQLiteSession.prepareQuery (./node_modules/.pnpm/drizzle-orm@0.30.8_@types+better-sqlite3@7.6.9_@types+react@18.2.79_better-sqlite3@9.5.0_react@18.2.0/node_modules/drizzle-orm/better-sqlite3/session.js:28:30)
    at BetterSQLiteSession.prepareOneTimeQuery (./node_modules/.pnpm/drizzle-orm@0.30.8_@types+better-sqlite3@7.6.9_@types+react@18.2.79_better-sqlite3@9.5.0_react@18.2.0/node_modules/drizzle-orm/sqlite-core/session.js:76:17)
    at QueryPromise._prepare (./node_modules/.pnpm/drizzle-orm@0.30.8_@types+better-sqlite3@7.6.9_@types+react@18.2.79_better-sqlite3@9.5.0_react@18.2.0/node_modules/drizzle-orm/sqlite-core/query-builders/insert.js:135:81)
    at QueryPromise.run (./node_modules/.pnpm/drizzle-orm@0.30.8_@types+better-sqlite3@7.6.9_@types+react@18.2.79_better-sqlite3@9.5.0_react@18.2.0/node_modules/drizzle-orm/sqlite-core/query-builders/insert.js:146:17)
    at QueryPromise.execute (./node_modules/.pnpm/drizzle-orm@0.30.8_@types+better-sqlite3@7.6.9_@types+react@18.2.79_better-sqlite3@9.5.0_react@18.2.0/node_modules/drizzle-orm/sqlite-core/query-builders/insert.js:158:54)
    at QueryPromise.then (./node_modules/.pnpm/drizzle-orm@0.30.8_@types+better-sqlite3@7.6.9_@types+react@18.2.79_better-sqlite3@9.5.0_react@18.2.0/node_modules/drizzle-orm/query-promise.js:26:17)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
digest: "3629522731"

Environment

drizzle-kit version: 0.20.17
drizzle-orm version: 0.30.8
framework: NextJS

Identified Bug:

The root cause of this error is the fact that the foriegn key values set up using the .references(()=>table.id) syntax in the schema are not being properly migrated, and are left referencing the _old_push version of the target table (which I assume only exists for a short time during the push:sqlite process)

Work Around:

The foriegn keys were not really neccessary in my case, so I just removed the .references() calls in the schema and everything works now, but I imagine that wont be a good solution for everyone.

@makerspeak
Copy link

Following. I get this a lot using local Turso dev. I end up having to recreate the local SQLite db and push from scratch but with so many changes whilst in dev, it gets frustrating. It's normally when I make changes to the relationships or the columns.

@dialnco
Copy link

dialnco commented Apr 22, 2024

+1. Same error running drizzle-kit push:sqlite with Turso. Very frustrating experience while on dev, as I have to instantiate new db on every schema changes for push:sqlite to run properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants