© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago•
1 reply
Cambaru

Creating DB with schema

I am pretty new to drizzle and try to follow the documentation. I found that you can initiallize drizzle with a schema like so:

import {drizzle} from "drizzle-orm/mysql2";
import mysql from "mysql2/promise";
import * as schema from './schema';

export const connection = await mysql.createConnection(
    process.env.DATABASE_CONNECTION as string
);

export const db = drizzle(connection,{schema});
import {drizzle} from "drizzle-orm/mysql2";
import mysql from "mysql2/promise";
import * as schema from './schema';

export const connection = await mysql.createConnection(
    process.env.DATABASE_CONNECTION as string
);

export const db = drizzle(connection,{schema});


./schema is my MySQL Database schema like so:

import {mysqlTable, varchar, int, boolean, timestamp} from 'drizzle-orm/mysql-core';

export const answers = mysqlTable('answers', {
    id: int('id').primaryKey().autoincrement(),
    text: varchar('text', { length: 2048 }).notNull(),
    correct: boolean('correct').notNull(),
    questionId: int('questionId').notNull()
        .references(() => questions.id),
});
... many more
import {mysqlTable, varchar, int, boolean, timestamp} from 'drizzle-orm/mysql-core';

export const answers = mysqlTable('answers', {
    id: int('id').primaryKey().autoincrement(),
    text: varchar('text', { length: 2048 }).notNull(),
    correct: boolean('correct').notNull(),
    questionId: int('questionId').notNull()
        .references(() => questions.id),
});
... many more



But i get this error wich i cannot explain:

TS2345: Argument of type '{ schema: typeof schema; }' is not assignable to parameter of type 'MySql2DrizzleConfig<typeof import("/home/...../lib/db/schema")> | undefined'.
Type '{ schema: typeof schema; }' is not assignable to type 'Omit<DrizzleConfig<typeof import("/home/...../lib/db/schema")>, "schema"> & { schema: typeof import("/home/...../lib/db/schema"); mode: Mode; }'.
Property 'mode' is missing in type '{ schema: typeof schema; }' but required in type '{ schema: typeof import("/home/...../lib/db/schema"); mode: Mode; }'.
TS2345: Argument of type '{ schema: typeof schema; }' is not assignable to parameter of type 'MySql2DrizzleConfig<typeof import("/home/...../lib/db/schema")> | undefined'.
Type '{ schema: typeof schema; }' is not assignable to type 'Omit<DrizzleConfig<typeof import("/home/...../lib/db/schema")>, "schema"> & { schema: typeof import("/home/...../lib/db/schema"); mode: Mode; }'.
Property 'mode' is missing in type '{ schema: typeof schema; }' but required in type '{ schema: typeof import("/home/...../lib/db/schema"); mode: Mode; }'.


I hope someone can help me 🙂
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Type for schema when creating db client
Drizzle TeamDTDrizzle Team / help
2y ago
Creating zod insert schema from Query with relations
Drizzle TeamDTDrizzle Team / help
3y ago
Get Schema From db instance
Drizzle TeamDTDrizzle Team / help
3y ago
Drizzle Kit: How to introspect Postgres DB without creating relations in generated schema?
Drizzle TeamDTDrizzle Team / help
2y ago