lettucebaran
lettucebaran
Explore posts from servers
DTDrizzle Team
Created by lettucebaran on 7/20/2024 in #help
Can't alter column from `.notNull()` to `allow null`
Background I have an SQLite db, and a schema.
// schema.ts
export const T1 = sqliteTable(
'T1',
{
// ...
C1: text('C1').notNull(),
// ...
},
);
// schema.ts
export const T1 = sqliteTable(
'T1',
{
// ...
C1: text('C1').notNull(),
// ...
},
);
I edited my schema to:
// schema.ts
export const T1 = sqliteTable(
'T1',
{
// ...
C1: text('C1'),
// ...
},
);
// schema.ts
export const T1 = sqliteTable(
'T1',
{
// ...
C1: text('C1'),
// ...
},
);
Aim Assuming the business logic is correct, I aimed to migrate my database with drizzle-kit generate and <apply migration script>. Problem However, after running the generate script, no migration was generated. How can I make C1 allow NULL values? Environment
"drizzle-kit": "^0.23.0",
"drizzle-orm": "^0.31.0",
"drizzle-kit": "^0.23.0",
"drizzle-orm": "^0.31.0",
Related SEO tags so others can find the problem and the solution quicker: NOT NULL constraint failed
4 replies
DTDrizzle Team
Created by lettucebaran on 6/4/2024 in #help
Type error when inserting
Aim insert row to contactInformationTable My attempt
// schema.ts
import { blob, integer, sqliteTable, text } from 'drizzle-orm/sqlite-core';
import { generateId } from 'lucia';

export const userTable = sqliteTable('user', {
id: text('id')
.notNull()
.primaryKey()
.$default(() => generateId(15)),
hashedPassword: text('hashed_password').notNull(),
});

export const contactInformationTable = sqliteTable('contact_information', {
userId: text('user_id')
.notNull()
.unique()
.references(() => userTable.id),
firstName: text('first_name'),
});
// schema.ts
import { blob, integer, sqliteTable, text } from 'drizzle-orm/sqlite-core';
import { generateId } from 'lucia';

export const userTable = sqliteTable('user', {
id: text('id')
.notNull()
.primaryKey()
.$default(() => generateId(15)),
hashedPassword: text('hashed_password').notNull(),
});

export const contactInformationTable = sqliteTable('contact_information', {
userId: text('user_id')
.notNull()
.unique()
.references(() => userTable.id),
firstName: text('first_name'),
});
// serverFunction.ts
await db
.insert(contactInformationTable)
.values({
userId: user.id,
firstName,
})
// serverFunction.ts
await db
.insert(contactInformationTable)
.values({
userId: user.id,
firstName,
})
// package.json
"drizzle-orm": "^0.31.0",
"drizzle-kit": "^0.21.4",
// package.json
"drizzle-orm": "^0.31.0",
"drizzle-kit": "^0.21.4",
7 replies
DTDrizzle Team
Created by lettucebaran on 5/20/2024 in #help
`drizzle-kit studio` is unable to launch D1 db (prod, remote)
Steps to reproduce: 1. Clone https://github.com/cjxe/nextjs-d1-drizzle-cloudflare-pages 2. Follow README.md. 3. Run pnpm db:studio:local. Verify that viewing the local d1 db is fine. 4. Run pnpm db:studio:prod. Verify that drizzle-kit is unable to view the d1 prod remote db. Error:
drizzle-kit: v0.21.2
drizzle-orm: v0.30.10

No config path provided, using default path
Reading config file '/Users/username/project/drizzle.config.ts'
Invalid input Either "turso", "libsql", "better-sqlite" are available options for "--driver"
 ELIFECYCLE  Command failed with exit code 1.
drizzle-kit: v0.21.2
drizzle-orm: v0.30.10

No config path provided, using default path
Reading config file '/Users/username/project/drizzle.config.ts'
Invalid input Either "turso", "libsql", "better-sqlite" are available options for "--driver"
 ELIFECYCLE  Command failed with exit code 1.
📁 drizzle.config.ts: https://github.com/cjxe/nextjs-d1-drizzle-cloudflare-pages/blob/main/drizzle.config.ts
2 replies