Drizzle Kit unable to migrate

Hello,

I have the following schema.ts file which is generating the following error:

~/project git:[master]
drizzle-kit migrate
drizzle-kit: v0.22.8
drizzle-orm: v0.31.2

No config path provided, using default path
Reading config file '/home/username/project/drizzle.config.ts'
Using 'postgres' driver for database querying
[⣷] applying migrations...{
  severity_local: 'NOTICE',
  severity: 'NOTICE',
  code: '42P06',
  message: 'schema "drizzle" already exists, skipping',
  file: 'schemacmds.c',
  line: '132',
  routine: 'CreateSchemaCommand'
}
{
  severity_local: 'NOTICE',
  severity: 'NOTICE',
  code: '42P07',
  message: 'relation "__drizzle_migrations" already exists, skipping',
  file: 'parse_utilcmd.c',
  line: '207',
  routine: 'transformCreateStmt'
}
{
  severity_local: 'NOTICE',
  severity: 'NOTICE',
  code: '42622',
  message: 'identifier "organization_guild_organization_id_organizations_organization_id_fk" will be truncated to "organization_guild_organization_id_organizations_organization_i"',
  where: 'compilation of PL/pgSQL function "inline_code_block" near line 1',
  file: 'scansup.c',
  line: '99',
  routine: 'truncate_identifier'
}
{
  severity_local: 'NOTICE',
  severity: 'NOTICE',
  code: '42622',
  message: 'identifier "organization_guild_organization_id_organizations_organization_id_fk" will be truncated to "organization_guild_organization_id_organizations_organization_i"',
  position: '15',
  file: 'scansup.c',
  line: '99',
  routine: 'truncate_identifier'
}
{
  severity_local: 'NOTICE',
  severity: 'NOTICE',
  code: '42622',
  message: 'identifier "organization_guild_organization_id_organizations_organization_id_fk" will be truncated to "organization_guild_organization_id_organizations_organization_i"',
  where: 'SQL statement "ALTER TABLE "organization_guild" ADD CONSTRAINT "organization_guild_organization_id_organizations_organization_id_fk" FOREIGN KEY ("organization_id") REFERENCES "public"."organizations"("organization_id") ON DELETE cascade ON UPDATE no action"\n' +
    'PL/pgSQL function inline_code_block line 2 at SQL statement',
  file: 'scansup.c',
  line: '99',
  routine: 'truncate_identifier'
}
PostgresError: there is no unique constraint matching given keys for referenced table "organizations"
    at ErrorResponse (/home/username/project/node_modules/drizzle-kit/bin.cjs:79677:27)
    at handle (/home/username/project/node_modules/drizzle-kit/bin.cjs:79454:7)
    at Socket.data (/home/username/project/node_modules/drizzle-kit/bin.cjs:79277:9)
    at Socket.emit (node:events:518:28)
    at addChunk (node:internal/streams/readable:559:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
    at Readable.push (node:internal/streams/readable:390:5)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
    at TCP.callbackTrampoline (node:internal/async_hooks:130:17) {
  severity_local: 'ERROR',
  severity: 'ERROR',
  code: '42830',
  where: 'SQL statement "ALTER TABLE "organization_guild" ADD CONSTRAINT "organization_guild_guild_id_organizations_guild_id_fk" FOREIGN KEY ("guild_id") REFERENCES "public"."organizations"("guild_id") ON DELETE cascade ON UPDATE no action"\n' +
    'PL/pgSQL function inline_code_block line 2 at SQL statement',
  file: 'tablecmds.c',
  line: '11583',
  routine: 'transformFkeyCheckAttrs'
}


I'm unsure how to proceed, this appears to be drizzle kit not correctly generating and migrating the constraints. I've also annexed the migration files
Was this page helpful?