drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
24.53k stars 643 forks source link

[BUG]: drizzle-kit push:sqlite fails to copy table data after adding a column #1313

Open yuraji opened 1 year ago

yuraji commented 1 year ago

What version of drizzle-orm are you using?

0.28.6(better-sqlite3@8.6.0)

What version of drizzle-kit are you using?

0.19.13

Describe the Bug

After adding a column to a table in schema, and executing drizzle-kit push:sqlite, it fails with error:
SqliteError: table posts has 4 columns but 3 values were supplied

In the database there's now __old_push_posts table, that the original posts table was renamed into, with all the data.

There's also now a new posts table with 4 columns, but no data.

The error message suggests that drizzle-kit fails to copy the data over after the change, because of the different number of columns.

Running push again, warns that it's going to delete the __old_push_posts, but I know that it contains the original data, not copied to the new posts table.

Expected behavior

drizzle-kit should be able to add a new column to a table in an sqlite db, with all the data intact, after adding a column to a table schema.

Environment & setup

Apple M1 Pro, Sonoma, Node v19.7.0

matannahmani commented 1 year ago

happens also here with turso ^^

yuraji commented 1 year ago

In the meanwhile, I'm manually restoring the data from the temporary column with something like

INSERT OR IGNORE INTO `posts` (`id`, `content`, `created`)
SELECT `id`, `content`, `created`
FROM `__old_push_posts`;

drizzle-kit should be doing something like that.

Oudwins commented 1 year ago

I am also having this error, and its very annoying :(

shriharip commented 11 months ago

Facing this issue with Turso. Added extra column to table and get this error

LibsqlError: SQLITE_UNKNOWN: SQLite error: table listings has 13 columns but 12 values were supplied
    at mapHranaError (file:///Users/shrihari/_/node_modules/.pnpm/@libsql+client@0.4.0-pre.2/node_modules/@libsql/client/lib-esm/hrana.js:257:16)
    at HttpClient.execute (file:///Users/shrihari/_/node_modules/.pnpm/@libsql+client@0.4.0-pre.2/node_modules/@libsql/client/lib-esm/http.js:53:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async TursoSqlite.run (/Users/shrihari/_/node_modules/.pnpm/drizzle-kit@0.20.6/node_modules/drizzle-kit/bin.cjs:25497:9)
    at async Command.<anonymous> (/Users/shrihari/_/node_modules/.pnpm/drizzle-kit@0.20.6/node_modules/drizzle-kit/bin.cjs:63284:9) {
  code: 'SQLITE_UNKNOWN',
  rawCode: undefined,
  [cause]: [ResponseError: SQLite error: table listings has 13 columns but 12 values were supplied] {
    code: 'SQLITE_UNKNOWN',
    proto: {
      message: 'SQLite error: table listings has 13 columns but 12 values were supplied',
      code: 'SQLITE_UNKNOWN'
    }
  }
}

(changed the project name to _ in the above)

"drizzle-kit": "^0.20.6", "drizzle-orm": "^0.29.0",

PhilBookst commented 11 months ago

is there any workaround until this is fixed?

matannahmani commented 10 months ago

any updates?

vim-diesel commented 10 months ago

don't understand what's happening. I got this same error after adding two columns to my schema and using drizzle-kit push:sqlite

panthyy commented 9 months ago

same problem

vim-diesel commented 9 months ago

After reading the docs, I can see that the push command is not intended to be used with production db's. It is only for local development, where you are expected to be able to delete the database and restart anytime you make a change.

shafayet035 commented 8 months ago

is there any update on this?

Alii-isk commented 7 months ago

any update?

kiikoh commented 6 months ago

This is issue is still occuring. I am using turso

Pramuspl commented 6 months ago

+1

brenden-js commented 6 months ago

Also happening here.

DeepjyotiDeb commented 5 months ago

Any updates for this issue? Specifically using turso in dev mode. Issue also occurs on tables that have a foreign key constraint. It is currently not possible to add a new table using the drizzle kit generate and migrate command.

itsanishjain commented 4 months ago

Woo still this issue, Suddenly everyone is using Turso, I just copy paste the generate sql into Turso SQL runner like this ALTER TABLE setting ADD enable_warning integer DEFAULT true;