strapi / migration-scripts

Collection of Strapi Migration scripts
58 stars 57 forks source link

Bug: Key (id)=(10234366) already exists. #81

Closed carloscip closed 1 year ago

carloscip commented 1 year ago

Bug report

Required System information

Describe the bug

It starts the migration process, but after a while restoring records in a specific table it gets stuck and shows this error (regarding duplicate ids, but original data does not have duplicate ids of course since its the PK):

duplicate key value violates unique constraint "node_states_pkey"
    at Parser.parseErrorMessage (/strapi-v3-v4-db-migration-scripts/v3-sql-v4-sql/node_modules/pg-protocol/dist/parser.js:287:98)
    at Parser.handlePacket (/strapi-v3-v4-db-migration-scripts/v3-sql-v4-sql/node_modules/pg-protocol/dist/parser.js:126:29)
    at Parser.parse (/strapi-v3-v4-db-migration-scripts/v3-sql-v4-sql/node_modules/pg-protocol/dist/parser.js:39:38)
    at Socket.<anonymous> (/strapi-v3-v4-db-migration-scripts/v3-sql-v4-sql/node_modules/pg-protocol/dist/index.js:11:42)
    at Socket.emit (node:events:527:28)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at Socket.Readable.push (node:internal/streams/readable:228:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
  length: 204,
  severity: 'ERROR',
  code: '23505',
  detail: 'Key (id)=(5440853) already exists.',
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: 'public',
  table: 'node_states',
  column: undefined,
  dataType: undefined,
  constraint: 'node_states_pkey',
  file: 'nbtinsert.c',
  line: '663',
  routine: '_bt_check_unique'
}
error Command failed with exit code 1.
damiepsz3 commented 1 year ago

hey @carloscip did you find any solution to this issue? I'm having it now, it seems related to the id auto-incremental and getting out-of-sync with it... but so far, I couldn't find a workaround.

gigiperih commented 1 year ago

same here, until now I don't have any fix or workaround.. what a shame

majoraze commented 1 year ago

I believe this merged PR adresses the error:

96

majoraze commented 1 year ago

But it's still happening on the migrateUsers.js file, I believe the same solution applies.

  for (var page = 0; page * BATCH_SIZE < count; page++) {
    console.log(`${source} batch #${page + 1}`);
    const items = await sourceSelect
      .clone()
      .limit(BATCH_SIZE)
      .offset(page * BATCH_SIZE)
      .orderBy('id', 'asc'); // adding this line but making the if statement to check if it's postgresql

    const migratedItems = migrateItems(
    ...
derrickmehaffy commented 1 year ago

fixed by: https://github.com/strapi/migration-scripts/pull/97