drizzle-team / drizzle-kit-mirror

Docs and issues repository for drizzle-kit
289 stars 17 forks source link

re-push does not work with the a composite primary key ( PostgreSQL code: 42704 ) #303

Open MrOxMasTer opened 9 months ago

MrOxMasTer commented 9 months ago

What version of drizzle-orm are you using? 0.29.3

What version of drizzle-kit are you using? 0.20.13

Describe the Bug

when using

export const productsToColors = pgTable(
  'productsToColors',
  {
    productId: integer('product_id')
      .notNull()
      .references(() => products.id),
    colorId: integer('color_id')
      .notNull()
      .references(() => colors.id),
  },
  (t) => {
    return {
      pk: primaryKey({ columns: [t.colorId, t.productId] }),
    };
  },
);

At the first migration, everything happens normally and no errors occur. But after I try to make a repeat push, then I get an error:

error: the restriction "products to colors_color_id_product_id_pk" does not exist in the "products To Colors" table

And an error from PostgreSQL:

at C:\Users\Alex\OneDrive\Desktop\PetProjects\shopco\node_modules\.pnpm\drizzle-kit@0.20.13\node_modules\drizzle-kit\bin.cjs:24462:21
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async PgPostgres.query (C:\Users\Alex\OneDrive\Desktop\PetProjects\shopco\node_modules\.pnpm\drizzle-kit@0.20.13\node_modules\drizzle-kit\bin.cjs:25423:21)
    at async Command.<anonymous> (C:\Users\Alex\OneDrive\Desktop\PetProjects\shopco\node_modules\.pnpm\drizzle-kit@0.20.13\node_modules\drizzle-kit\bin.cjs:63260:9) {
  length: 204,
  severity: 'Error',
  code: '42704',
  detail: undefined,
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'tablecmds.c',
  line: '12030',
  routine: 'ATExecDropConstraint'
}
MrOxMasTer commented 9 months ago

if you add the name primary Key, everything will be fine, but I don't know if this is normal behavior, but I don't have this primary key displayed in drizzle studio and pgAdmin

   return {
      pk: primaryKey({ columns: [t.colorId, t.productId], name: 'id' }),
    };

image