next-learn icon indicating copy to clipboard operation
next-learn copied to clipboard

Chapter 6: The lib file to seed the db contains duplicate ID values

Open Razr6 opened this issue 1 year ago • 6 comments

in placeholder-data.ts 👍

{ id: '3958dc9e-712f-4377-85e9-fec4b6a6442a', name: 'Delba de Oliveira', email: '[email protected]', image_url: '/customers/delba-de-oliveira.png', }, { id: '3958dc9e-742f-4377-85e9-fec4b6a6442a', name: 'Lee Robinson', email: '[email protected]', image_url: '/customers/lee-robinson.png', },

because id must be unique, the db seeding fails, with the error (I am on Neon) of:

{ "error": { "name": "PostgresError", "severity_local": "ERROR", "severity": "ERROR", "code": "23505", "detail": "Key (extname)=(uuid-ossp) already exists.", "schema_name": "pg_catalog", "table_name": "pg_extension", "constraint_name": "pg_extension_name_index", "file": "nbtinsert.c", "line": "664", "routine": "_bt_check_unique" } }

Razr6 avatar Feb 12 '25 11:02 Razr6

id: '3958dc9e-712f-4377-85e9-fec4b6a6442a', and id: '3958dc9e-742f-4377-85e9-fec4b6a6442a', seems different tho?

DavidCWHung avatar Feb 24 '25 23:02 DavidCWHung

This might be because you're already ran the seeding process and the data is in the DB. Could you check?

leerob avatar Feb 25 '25 17:02 leerob

Sorry, I'm a newb and am just struggling my way through the tutorial, for the fourth time. I can't now tell if I had seeded it once or twice, when this happened.

When I first got the error, I looked about, looked in the db files and as far as I can I remember, the other tables had all seeded ok but the customer table was simply not there. And then I thought I had traced the problem back to the data in the placeholder-data.ts file. But as DavidCWHung points out the IDs are actually different - by just 1x character, buried in the middle of a 36 chr string (?).

Anyway. So I guess I was wrong. Looks like I am probably wasting your time here.

Razr6 avatar Feb 25 '25 18:02 Razr6

@leerob I experienced the same issue today when doing the tutorial...I've sent along a PR (#1013) for review which when applied fixed the problem for me....hope it helps.

w0244079 avatar Feb 26 '25 18:02 w0244079

I also ran into problems seeding (somehow missing the invoice in the chapter 6 query, and fewer than expected customers). @w0244079 Your fix worked for me, thank you. I can move on to chapter 7 now 🥇

chrissygonzalez avatar Mar 03 '25 19:03 chrissygonzalez

change placeholder-data 'id' to other name. for example:

const users = [
  {
    user_id: '410544b2-4001-4271-9855-fec4b6a6442a',
    name: 'User',
    email: '[email protected]',
    password: '123456',
  },
];

const customers = [
  {
    user_id: 'd6e15727-9fe1-4961-8c5b-ea44a9bd81aa',
    name: 'Evil Rabbit',
    email: '[email protected]',
    image_url: '/customers/evil-rabbit.png',
  },

then fix 'seed/route.ts' error

kRadius avatar Jun 16 '25 14:06 kRadius