migration problem

Hello everybody, this is my first time using drizzle and using an sql library for the first time. I was wondering why am I getting this error?
[⣯] applying migrations...LibsqlError: SQL_INPUT_ERROR: SQL input error: table `platforms` already exists (at offset 13)
at mapHranaError (file:///Users/bobasafe/DevLink/Link-Sharing/linksharing/node_modules/@libsql/client/lib-esm/hrana.js:262:16)
at HttpClient.batch (file:///Users/bobasafe/DevLink/Link-Sharing/linksharing/node_modules/@libsql/client/lib-esm/http.js:118:19)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at LibSQLSession.batch (/Users/bobasafe/DevLink/Link-Sharing/linksharing/node_modules/src/libsql/session.ts:75:24)
at migrate (/Users/bobasafe/DevLink/Link-Sharing/linksharing/node_modules/src/libsql/migrator.ts:50:2) {
code: 'SQL_INPUT_ERROR',
rawCode: undefined,
[cause]: [ResponseError: SQL input error: table `platforms` already exists (at offset 13)] {
code: 'SQL_INPUT_ERROR',
proto: {
message: 'SQL input error: table `platforms` already exists (at offset 13)',
code: 'SQL_INPUT_ERROR'
}
}
}
[⣯] applying migrations...LibsqlError: SQL_INPUT_ERROR: SQL input error: table `platforms` already exists (at offset 13)
at mapHranaError (file:///Users/bobasafe/DevLink/Link-Sharing/linksharing/node_modules/@libsql/client/lib-esm/hrana.js:262:16)
at HttpClient.batch (file:///Users/bobasafe/DevLink/Link-Sharing/linksharing/node_modules/@libsql/client/lib-esm/http.js:118:19)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at LibSQLSession.batch (/Users/bobasafe/DevLink/Link-Sharing/linksharing/node_modules/src/libsql/session.ts:75:24)
at migrate (/Users/bobasafe/DevLink/Link-Sharing/linksharing/node_modules/src/libsql/migrator.ts:50:2) {
code: 'SQL_INPUT_ERROR',
rawCode: undefined,
[cause]: [ResponseError: SQL input error: table `platforms` already exists (at offset 13)] {
code: 'SQL_INPUT_ERROR',
proto: {
message: 'SQL input error: table `platforms` already exists (at offset 13)',
code: 'SQL_INPUT_ERROR'
}
}
}
I deleted the migration folder (because i was looking up the discord to see if anyone has the same issue), generated it, and once I used the migrate command it it gave me this error
9 Replies
boba
bobaOP3mo ago
here is the migration file
CREATE TABLE `platforms` (
`id` text PRIMARY KEY NOT NULL,
`created_at` text DEFAULT CURRENT_TIMESTAMP NOT NULL,
`profile_id` text,
`name` text NOT NULL,
`link` text NOT NULL,
FOREIGN KEY (`profile_id`) REFERENCES `profiles`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `profiles` (
`id` text PRIMARY KEY NOT NULL,
`created_at` text DEFAULT CURRENT_TIMESTAMP NOT NULL,
`user_id` text,
`email` text NOT NULL,
`first_name` text NOT NULL,
`last_name` text NOT NULL,
`presigned_url` text,
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `users` (
`id` text PRIMARY KEY NOT NULL,
`created_at` text DEFAULT CURRENT_TIMESTAMP NOT NULL,
`email` text NOT NULL,
`password` text NOT NULL
);
--> statement-breakpoint
CREATE UNIQUE INDEX `profiles_user_id_unique` ON `profiles` (`user_id`);--> statement-breakpoint
CREATE UNIQUE INDEX `users_email_unique` ON `users` (`email`);
CREATE TABLE `platforms` (
`id` text PRIMARY KEY NOT NULL,
`created_at` text DEFAULT CURRENT_TIMESTAMP NOT NULL,
`profile_id` text,
`name` text NOT NULL,
`link` text NOT NULL,
FOREIGN KEY (`profile_id`) REFERENCES `profiles`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `profiles` (
`id` text PRIMARY KEY NOT NULL,
`created_at` text DEFAULT CURRENT_TIMESTAMP NOT NULL,
`user_id` text,
`email` text NOT NULL,
`first_name` text NOT NULL,
`last_name` text NOT NULL,
`presigned_url` text,
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `users` (
`id` text PRIMARY KEY NOT NULL,
`created_at` text DEFAULT CURRENT_TIMESTAMP NOT NULL,
`email` text NOT NULL,
`password` text NOT NULL
);
--> statement-breakpoint
CREATE UNIQUE INDEX `profiles_user_id_unique` ON `profiles` (`user_id`);--> statement-breakpoint
CREATE UNIQUE INDEX `users_email_unique` ON `users` (`email`);
Anyone?
Dush
Dush3mo ago
Your db has already created those tables, A simple solution if you are new to drizzle and sql is to drop the tables from the database and try to migrate again
boba
bobaOP3mo ago
That should work but what if I want to make changes just by simply adding another column into my table for example I added a presignedurl col I don't think dropping the tables would be nice
🇨🇭 Marko Bolliger <cannap>
i think they work on new migrations i dont i just get troubles currently my project is dev only after it go in production i get fucked i think my migrations 😄
boba
bobaOP3mo ago
huh
boba
bobaOP3mo ago
hey
mediumhype
mediumhype3mo ago
Your migration script is trying to create the table, but it already exists. There are several reasons for why this might be the case, but bottom line your database is out of sync with your migration script. Possible fixes are: - Change the database to remove the inconsistencies (DROP TABLE) - Change the migration scripts (e.g. CREATE [IF NOT EXISTS])
boba
bobaOP2mo ago
i followed but i keep getting this
[⣷] applying migrations...result: Response {
status: 400,
statusText: 'Bad Request',
headers: Headers {
'access-control-allow-origin': '*',
'content-type': 'application/json',
date: 'Fri, 13 Sep 2024 08:01:19 GMT',
'fly-request-id': '01J7N6D7H4AY9SA9YARQ4H1PR8-sjc',
server: 'Fly/0049c9a9 (2024-09-10)',
'server-timing': 'query_total;dur=258.371µs,',
vary: 'origin, access-control-request-method, access-control-request-headers',
via: '2 fly.io, 1.1 fly.io',
'transfer-encoding': 'chunked',
'content-encoding': 'br'
},
body: ReadableStream { locked: false, state: 'readable', supportsBYOB: true },
bodyUsed: false,
ok: false,
redirected: false,
type: 'basic',
url: 'https://linksharing-safepre.turso.io/v1/jobs'
}
[⣷] applying migrations...result: Response {
status: 400,
statusText: 'Bad Request',
headers: Headers {
'access-control-allow-origin': '*',
'content-type': 'application/json',
date: 'Fri, 13 Sep 2024 08:01:19 GMT',
'fly-request-id': '01J7N6D7H4AY9SA9YARQ4H1PR8-sjc',
server: 'Fly/0049c9a9 (2024-09-10)',
'server-timing': 'query_total;dur=258.371µs,',
vary: 'origin, access-control-request-method, access-control-request-headers',
via: '2 fly.io, 1.1 fly.io',
'transfer-encoding': 'chunked',
'content-encoding': 'br'
},
body: ReadableStream { locked: false, state: 'readable', supportsBYOB: true },
bodyUsed: false,
ok: false,
redirected: false,
type: 'basic',
url: 'https://linksharing-safepre.turso.io/v1/jobs'
}
heres my config file
import 'dotenv/config'
import type { Config } from 'drizzle-kit'

export default {
schema: './db/schema.ts',
out: './migrations',
driver: 'turso',
dbCredentials: {
url: process.env.TURSO_CONNECTION_URL!,
authToken: process.env.TURSO_AUTH_TOKEN!,
},
verbose: true,
strict: true,
dialect: 'sqlite',
} satisfies Config
import 'dotenv/config'
import type { Config } from 'drizzle-kit'

export default {
schema: './db/schema.ts',
out: './migrations',
driver: 'turso',
dbCredentials: {
url: process.env.TURSO_CONNECTION_URL!,
authToken: process.env.TURSO_AUTH_TOKEN!,
},
verbose: true,
strict: true,
dialect: 'sqlite',
} satisfies Config
Any1 Is there a reason why its giving me a bad request when i use the migrate command?
Want results from more Discord servers?
Add your server