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]: SQLite migration fails when adding field with autoincrement #3801

Open
1 task done
valterkraemer opened this issue Dec 18, 2024 · 0 comments
Open
1 task done
Labels
bug Something isn't working db/sqlite drizzle/kit priority Will be worked on next

Comments

@valterkraemer
Copy link

Report hasn't been filed before.

  • I have verified that the bug I'm about to report hasn't been filed before.

What version of drizzle-orm are you using?

0.38.2

What version of drizzle-kit are you using?

0.30.1

Other packages

No response

Describe the Bug

I have this schema:

export const sessions = sqliteTable("sessions", {
	token: text({
		length: 255,
	}),
});

I then add an id field with autoIncrement

export const sessions = sqliteTable("sessions", {
	id: integer().primaryKey({
		autoIncrement: true,
	}),
	token: text({
		length: 255,
	}),
});

Results in this migration:

PRAGMA foreign_keys=OFF;--> statement-breakpoint
CREATE TABLE `__new_sessions` (
	`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
	`token` text(255)
);
--> statement-breakpoint
INSERT INTO `__new_sessions`("id", "token") SELECT "id", "token" FROM `sessions`;--> statement-breakpoint
DROP TABLE `sessions`;--> statement-breakpoint
ALTER TABLE `__new_sessions` RENAME TO `sessions`;--> statement-breakpoint
PRAGMA foreign_keys=ON;

But this migration fails.

When I modify the following line to remove id

INSERT INTO `__new_sessions`("token") SELECT "token" FROM `sessions`;--> statement-breakpoint

it works.

@valterkraemer valterkraemer added the bug Something isn't working label Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working db/sqlite drizzle/kit priority Will be worked on next
Projects
None yet
Development

No branches or pull requests

2 participants