FelixNg
FelixNg
DTDrizzle Team
Created by FelixNg on 1/30/2024 in #help
Foreign keys default to NOT NULL with PostgreSQL
I currently have these two tables. I don't understand why Drizzle keeps generating foreign keys with the NOT NULL constraints. I'd really appreciate any help regarding this, been bashing my head against the keyboard for so many hours now. Thanks a lot.
export const assetTable = pgTable(
'asset',
{
id: serial('id').primaryKey(),
},
);

export const trackTable = pgTable(
'track',
{
id: serial('id').primaryKey(),
// TODO: investigate why foreign keys default to NOT NULL
originalAssetId: serial('original_asset_id').references(
() => assetTable.id,
{
onDelete: 'cascade',
},
),
},
);
export const assetTable = pgTable(
'asset',
{
id: serial('id').primaryKey(),
},
);

export const trackTable = pgTable(
'track',
{
id: serial('id').primaryKey(),
// TODO: investigate why foreign keys default to NOT NULL
originalAssetId: serial('original_asset_id').references(
() => assetTable.id,
{
onDelete: 'cascade',
},
),
},
);
Below is the generated migration file
CREATE TABLE IF NOT EXISTS "asset" (
"id" serial PRIMARY KEY NOT NULL,
);

CREATE TABLE IF NOT EXISTS "track" (
"id" serial PRIMARY KEY NOT NULL,
"original_asset_id" serial NOT NULL,
);
CREATE TABLE IF NOT EXISTS "asset" (
"id" serial PRIMARY KEY NOT NULL,
);

CREATE TABLE IF NOT EXISTS "track" (
"id" serial PRIMARY KEY NOT NULL,
"original_asset_id" serial NOT NULL,
);
5 replies
DTDrizzle Team
Created by FelixNg on 11/24/2023 in #help
createInsertSchema & createSelectSchema difference
I am using drizzle-zod along with sveltekit-superforms and thoroughly enjoying the combo so far. One question I have is that what is the fundamental difference between the two functions above. I didn't find any related questions or documentation. I think they are mostly the same. taking in a drizzle schema and returning a zod object. Is it just a difference in semantics? I'll appreciate any input on this.
4 replies