payload
payload copied to clipboard
create-payload-app@beta data seeding broken
Describe the Bug
I created a brand-new app and connected to a Vercel-managed Postgres instance. I opened the admin panel and clicked the seed button. Seeding fails with this error while adding the related posts to the first post:
[16:01:02] ERROR: Error validating filter options for collection posts
err: {
"type": "NotFound",
"message": "Not Found",
"stack":
NotFound: Not Found
at findByIDOperation (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected][email protected][email protected][email protected]_cawqsxv2rsw3o2qcs57mgzb6au/node_modules/payload/dist/collections/operations/findByID.js:70:23)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async populateAuthors (webpack-internal:///(rsc)/./src/collections/Posts/hooks/populateAuthors.ts:13:31)
at async eval (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected][email protected][email protected][email protected]_cawqsxv2rsw3o2qcs57mgzb6au/node_modules/payload/dist/collections/operations/find.js:205:30)
at async eval (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected][email protected][email protected][email protected]_cawqsxv2rsw3o2qcs57mgzb6au/node_modules/payload/dist/collections/operations/find.js:203:17)
at async Promise.all (index 1)
at async findOperation (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected][email protected][email protected][email protected]_cawqsxv2rsw3o2qcs57mgzb6au/node_modules/payload/dist/collections/operations/find.js:201:19)
at async validateFilterOptions (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected][email protected][email protected][email protected]_cawqsxv2rsw3o2qcs57mgzb6au/node_modules/payload/dist/fields/validations.js:404:36)
at async promise (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected][email protected][email protected][email protected]_cawqsxv2rsw3o2qcs57mgzb6au/node_modules/payload/dist/fields/hooks/beforeChange/promise.js:84:38)
at async Promise.all (index 0)
at async traverseFields (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected][email protected][email protected][email protected]_cawqsxv2rsw3o2qcs57mgzb6au/node_modules/payload/dist/fields/hooks/beforeChange/traverseFields.js:38:5)
at async promise (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected][email protected][email protected][email protected]_cawqsxv2rsw3o2qcs57mgzb6au/node_modules/payload/dist/fields/hooks/beforeChange/promise.js:309:17)
at async Promise.all (index 1)
at async traverseFields (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected][email protected][email protected][email protected]_cawqsxv2rsw3o2qcs57mgzb6au/node_modules/payload/dist/fields/hooks/beforeChange/traverseFields.js:38:5)
at async promise (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected][email protected][email protected][email protected]_cawqsxv2rsw3o2qcs57mgzb6au/node_modules/payload/dist/fields/hooks/beforeChange/promise.js:333:17)
at async Promise.all (index 1)
at async traverseFields (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected][email protected][email protected][email protected]_cawqsxv2rsw3o2qcs57mgzb6au/node_modules/payload/dist/fields/hooks/beforeChange/traverseFields.js:38:5)
at async beforeChange (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected][email protected][email protected][email protected]_cawqsxv2rsw3o2qcs57mgzb6au/node_modules/payload/dist/fields/hooks/beforeChange/index.js:22:5)
at async updateByIDOperation (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected][email protected][email protected][email protected]_cawqsxv2rsw3o2qcs57mgzb6au/node_modules/payload/dist/collections/operations/updateByID.js:253:22)
at async seed (webpack-internal:///(rsc)/./src/endpoints/seed/index.ts:267:5)
at async Object.seedHandler [as handler] (webpack-internal:///(rsc)/./src/endpoints/seedHandler.ts:22:9)
at async handleCustomEndpoints (webpack-internal:///(rsc)/./node_modules/.pnpm/@[email protected][email protected][email protected][email protected]_next@15._wfgcrxf5fm4ki4drr4c2hbztpi/node_modules/@payloadcms/next/dist/routes/rest/index.js:198:19)
at async eval (webpack-internal:///(rsc)/./node_modules/.pnpm/@[email protected][email protected][email protected][email protected]_next@15._wfgcrxf5fm4ki4drr4c2hbztpi/node_modules/@payloadcms/next/dist/routes/rest/index.js:420:36)
at async AppRouteRouteModule.do (/home/stevekuznetsov/code/NWACus/website/src/github.com/NWACus/website/node_modules/.pnpm/[email protected][email protected][email protected]__react@19_7kfqem4pd6aim6nxuy4v6dxrry/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:10:32709)
at async AppRouteRouteModule.handle (/home/stevekuznetsov/code/NWACus/website/src/github.com/NWACus/website/node_modules/.pnpm/[email protected][email protected][email protected]__react@19_7kfqem4pd6aim6nxuy4v6dxrry/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:10:38210)
at async doRender (/home/stevekuznetsov/code/NWACus/website/src/github.com/NWACus/website/node_modules/.pnpm/[email protected][email protected][email protected]__react@19_7kfqem4pd6aim6nxuy4v6dxrry/node_modules/next/dist/server/base-server.js:1493:42)
at async responseGenerator (/home/stevekuznetsov/code/NWACus/website/src/github.com/NWACus/website/node_modules/.pnpm/[email protected][email protected][email protected]__react@19_7kfqem4pd6aim6nxuy4v6dxrry/node_modules/next/dist/server/base-server.js:1834:28)
at async DevServer.renderToResponseWithComponentsImpl (/home/stevekuznetsov/code/NWACus/website/src/github.com/NWACus/website/node_modules/.pnpm/[email protected][email protected][email protected]__react@19_7kfqem4pd6aim6nxuy4v6dxrry/node_modules/next/dist/server/base-server.js:1878:28)
at async DevServer.renderPageComponent (/home/stevekuznetsov/code/NWACus/website/src/github.com/NWACus/website/node_modules/.pnpm/[email protected][email protected][email protected]__react@19_7kfqem4pd6aim6nxuy4v6dxrry/node_modules/next/dist/server/base-server.js:2292:24)
at async DevServer.renderToResponseImpl (/home/stevekuznetsov/code/NWACus/website/src/github.com/NWACus/website/node_modules/.pnpm/[email protected][email protected][email protected]__react@19_7kfqem4pd6aim6nxuy4v6dxrry/node_modules/next/dist/server/base-server.js:2330:32)
at async DevServer.pipeImpl (/home/stevekuznetsov/code/NWACus/website/src/github.com/NWACus/website/node_modules/.pnpm/[email protected][email protected][email protected]__react@19_7kfqem4pd6aim6nxuy4v6dxrry/node_modules/next/dist/server/base-server.js:984:25)
at async NextNodeServer.handleCatchallRenderRequest (/home/stevekuznetsov/code/NWACus/website/src/github.com/NWACus/website/node_modules/.pnpm/[email protected][email protected][email protected]__react@19_7kfqem4pd6aim6nxuy4v6dxrry/node_modules/next/dist/server/next-server.js:281:17)
at async DevServer.handleRequestImpl (/home/stevekuznetsov/code/NWACus/website/src/github.com/NWACus/website/node_modules/.pnpm/[email protected][email protected][email protected]__react@19_7kfqem4pd6aim6nxuy4v6dxrry/node_modules/next/dist/server/base-server.js:877:17)
at async /home/stevekuznetsov/code/NWACus/website/src/github.com/NWACus/website/node_modules/.pnpm/[email protected][email protected][email protected]__react@19_7kfqem4pd6aim6nxuy4v6dxrry/node_modules/next/dist/server/dev/next-dev-server.js:373:20
at async Span.traceAsyncFn (/home/stevekuznetsov/code/NWACus/website/src/github.com/NWACus/website/node_modules/.pnpm/[email protected][email protected][email protected]__react@19_7kfqem4pd6aim6nxuy4v6dxrry/node_modules/next/dist/trace/trace.js:157:20)
at async DevServer.handleRequest (/home/stevekuznetsov/code/NWACus/website/src/github.com/NWACus/website/node_modules/.pnpm/[email protected][email protected][email protected]__react@19_7kfqem4pd6aim6nxuy4v6dxrry/node_modules/next/dist/server/dev/next-dev-server.js:370:24)
at async invokeRender (/home/stevekuznetsov/code/NWACus/website/src/github.com/NWACus/website/node_modules/.pnpm/[email protected][email protected][email protected]__react@19_7kfqem4pd6aim6nxuy4v6dxrry/node_modules/next/dist/server/lib/router-server.js:183:21)
at async handleRequest (/home/stevekuznetsov/code/NWACus/website/src/github.com/NWACus/website/node_modules/.pnpm/[email protected][email protected][email protected]__react@19_7kfqem4pd6aim6nxuy4v6dxrry/node_modules/next/dist/server/lib/router-server.js:360:24)
at async requestHandlerImpl (/home/stevekuznetsov/code/NWACus/website/src/github.com/NWACus/website/node_modules/.pnpm/[email protected][email protected][email protected]__react@19_7kfqem4pd6aim6nxuy4v6dxrry/node_modules/next/dist/server/lib/router-server.js:384:13)
at async Server.requestListener (/home/stevekuznetsov/code/NWACus/website/src/github.com/NWACus/website/node_modules/.pnpm/[email protected][email protected][email protected]__react@19_7kfqem4pd6aim6nxuy4v6dxrry/node_modules/next/dist/server/lib/start-server.js:142:13)
"data": null,
"isOperational": true,
"isPublic": false,
"status": 404,
"name": "NotFound"
}
GET /api/seed 500 in 20353ms
[16:01:02] ERROR: The following field is invalid: relatedPosts
I've added loads of debugging information and I can fetch all of the posts, cycle through them and execute the meat of the populateAuthors logic - fetching the authors - with no issue whatsoever. As far as I can tell there is nothing in the posts table after this script runs and fails.
Link to the code that reproduces this issue
https://github.com/NWACus/website/commit/5a9b520f30b86b663f57cb0334c90930189402eb#diff-ec70d248db3563b095d5b75fc9c001d30a315e4b2e01e920277bb1c1261adfe5R238
Reproduction Steps
npx create-payload-app@beta website -t website
# use the Vercel Postgres option for storage, add a connection string
pnpm install && pnpm dev
# open the admin panel and click on seed
Which area(s) are affected? (Select all that apply)
area: templates
Environment Info
$ pnpm payload info
[email protected] payload /home/stevekuznetsov/code/NWACus/website/src/github.com/NWACus/website
cross-env NODE_OPTIONS=--no-deprecation payload "info"
Binaries:
Node: 20.17.0
npm: 10.8.2
Yarn: 1.22.22
pnpm: 9.12.2
Relevant Packages:
payload: 3.0.0-beta.119
next: 15.0.0
@payloadcms/email-nodemailer: 3.0.0-beta.119
@payloadcms/graphql: 3.0.0-beta.119
@payloadcms/live-preview: 3.0.0-beta.119
@payloadcms/live-preview-react: 3.0.0-beta.119
@payloadcms/next/utilities: 3.0.0-beta.119
@payloadcms/payload-cloud: 3.0.0-beta.119
@payloadcms/plugin-form-builder: 3.0.0-beta.119
@payloadcms/plugin-nested-docs: 3.0.0-beta.119
@payloadcms/plugin-redirects: 3.0.0-beta.119
@payloadcms/plugin-search: 3.0.0-beta.119
@payloadcms/plugin-seo: 3.0.0-beta.119
@payloadcms/richtext-lexical: 3.0.0-beta.119
@payloadcms/translations: 3.0.0-beta.119
@payloadcms/ui/shared: 3.0.0-beta.119
react: 19.0.0-rc-65a56d0e-20241020
react-dom: 19.0.0-rc-65a56d0e-20241020
Operating System:
Platform: linux
Arch: x64
Version: #1 SMP PREEMPT_DYNAMIC Thu Oct 10 22:31:19 UTC 2024
Available memory (MB): 64191
Available CPU cores: 16
Hey! We couldn't reproduce your issue, I tried:
- Fresh instance from
npx create-payload-app@beta -t websiteusing the postgres vercel adapter. - Your repository, I ran
npm i --force(as you havepackage-lock.json),pnpm dev, clicked "seed" and it worked for me.
Hey @stevekuznetsov & @r1tsuu!
I've also encountered this exact issue during a new project setup today.
Steps to Reproduce:
- Created a fresh PostgreSQL database on Vercel and copied the connection string
postgres://default:************@************:5432/verceldb?sslmode=require. - Created a new directory and ran
npx create-payload-app@beta -t website. - Entered project name, selected database "Vercel Postgres (beta)", pasted Vercel connection string and waited for installation to complete.
- Started app with
pnpm dev. - Visited
localhost:3000/admin, created a new user, and logged in. - Clicked the seed database link, which after a few seconds showed that the seeding was successful, but the console returned the following:
[15:27:39] INFO: Seeding database...
[15:27:39] INFO: — Clearing media...
[15:27:39] INFO: — Clearing collections and globals...
[15:27:39] INFO: Revalidating header
[15:27:39] INFO: Revalidating footer
{ pages: { docs: [], errors: [] } }
[15:27:40] INFO: — Seeding demo author and user...
[15:27:41] INFO: — Seeding media...
[15:27:42] INFO: — Seeding categories...
[15:27:45] INFO: — Seeding posts...
[15:27:46] INFO: Revalidating post at path: /posts/digital-horizons
[15:27:46] INFO: Revalidating post at path: /posts/global-gaze
[15:27:47] INFO: Revalidating post at path: /posts/dollar-and-sense-the-financial-forecast
[15:27:48] ERROR: Error validating filter options for collection posts
err: {
"type": "NotFound",
"message": "Not Found",
"stack":
NotFound: Not Found
at findByIDOperation (webpack-internal:///(rsc)/./node_modules/payload/dist/collections/operations/findByID.js:71:23)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async populateAuthors (webpack-internal:///(rsc)/./src/collections/Posts/hooks/populateAuthors.ts:13:31)
at async eval (webpack-internal:///(rsc)/./node_modules/payload/dist/collections/operations/find.js:230:30)
at async eval (webpack-internal:///(rsc)/./node_modules/payload/dist/collections/operations/find.js:228:17)
at async Promise.all (index 1)
at async findOperation (webpack-internal:///(rsc)/./node_modules/payload/dist/collections/operations/find.js:226:19)
at async validateFilterOptions (webpack-internal:///(rsc)/./node_modules/payload/dist/fields/validations.js:404:36)
at async promise (webpack-internal:///(rsc)/./node_modules/payload/dist/fields/hooks/beforeChange/promise.js:84:38)
at async Promise.all (index 0)
at async traverseFields (webpack-internal:///(rsc)/./node_modules/payload/dist/fields/hooks/beforeChange/traverseFields.js:38:5)
at async promise (webpack-internal:///(rsc)/./node_modules/payload/dist/fields/hooks/beforeChange/promise.js:309:17)
at async Promise.all (index 1)
at async traverseFields (webpack-internal:///(rsc)/./node_modules/payload/dist/fields/hooks/beforeChange/traverseFields.js:38:5)
at async promise (webpack-internal:///(rsc)/./node_modules/payload/dist/fields/hooks/beforeChange/promise.js:333:17)
at async Promise.all (index 1)
at async traverseFields (webpack-internal:///(rsc)/./node_modules/payload/dist/fields/hooks/beforeChange/traverseFields.js:38:5)
at async beforeChange (webpack-internal:///(rsc)/./node_modules/payload/dist/fields/hooks/beforeChange/index.js:22:5)
at async updateByIDOperation (webpack-internal:///(rsc)/./node_modules/payload/dist/collections/operations/updateByID.js:253:22)
at async seed (webpack-internal:///(rsc)/./src/endpoints/seed/index.ts:225:5)
at async Object.seedHandler [as handler] (webpack-internal:///(rsc)/./src/endpoints/seedHandler.ts:22:9)
at async handleCustomEndpoints (webpack-internal:///(rsc)/./node_modules/@payloadcms/next/dist/routes/rest/index.js:198:19)
at async eval (webpack-internal:///(rsc)/./node_modules/@payloadcms/next/dist/routes/rest/index.js:420:36)
at async AppRouteRouteModule.do (/home/ben/projects/bato-web-app/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:10:32709)
at async AppRouteRouteModule.handle (/home/ben/projects/bato-web-app/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:10:38210)
at async doRender (/home/ben/projects/bato-web-app/node_modules/next/dist/server/base-server.js:1493:42)
at async responseGenerator (/home/ben/projects/bato-web-app/node_modules/next/dist/server/base-server.js:1834:28)
at async DevServer.renderToResponseWithComponentsImpl (/home/ben/projects/bato-web-app/node_modules/next/dist/server/base-server.js:1878:28)
at async DevServer.renderPageComponent (/home/ben/projects/bato-web-app/node_modules/next/dist/server/base-server.js:2292:24)
at async DevServer.renderToResponseImpl (/home/ben/projects/bato-web-app/node_modules/next/dist/server/base-server.js:2330:32)
at async DevServer.pipeImpl (/home/ben/projects/bato-web-app/node_modules/next/dist/server/base-server.js:984:25)
at async NextNodeServer.handleCatchallRenderRequest (/home/ben/projects/bato-web-app/node_modules/next/dist/server/next-server.js:281:17)
at async DevServer.handleRequestImpl (/home/ben/projects/bato-web-app/node_modules/next/dist/server/base-server.js:877:17)
at async /home/ben/projects/bato-web-app/node_modules/next/dist/server/dev/next-dev-server.js:373:20
at async Span.traceAsyncFn (/home/ben/projects/bato-web-app/node_modules/next/dist/trace/trace.js:157:20)
at async DevServer.handleRequest (/home/ben/projects/bato-web-app/node_modules/next/dist/server/dev/next-dev-server.js:370:24)
at async invokeRender (/home/ben/projects/bato-web-app/node_modules/next/dist/server/lib/router-server.js:183:21)
at async handleRequest (/home/ben/projects/bato-web-app/node_modules/next/dist/server/lib/router-server.js:360:24)
at async requestHandlerImpl (/home/ben/projects/bato-web-app/node_modules/next/dist/server/lib/router-server.js:384:13)
at async Server.requestListener (/home/ben/projects/bato-web-app/node_modules/next/dist/server/lib/start-server.js:142:13)
"data": null,
"isOperational": true,
"isPublic": false,
"status": 404,
"name": "NotFound"
}
GET /api/seed 500 in 9379ms
[15:27:48] ERROR: The following field is invalid: relatedPosts
Environment Info
Binaries:
Node: 20.10.0
npm: 10.2.3
Yarn: 1.22.22
pnpm: 9.4.0
Relevant Packages:
payload: 3.0.0-beta.123
next: 15.0.0
@payloadcms/email-nodemailer: 3.0.0-beta.123
@payloadcms/graphql: 3.0.0-beta.123
@payloadcms/live-preview: 3.0.0-beta.123
@payloadcms/live-preview-react: 3.0.0-beta.123
@payloadcms/next/utilities: 3.0.0-beta.123
@payloadcms/payload-cloud: 3.0.0-beta.123
@payloadcms/plugin-form-builder: 3.0.0-beta.123
@payloadcms/plugin-nested-docs: 3.0.0-beta.123
@payloadcms/plugin-redirects: 3.0.0-beta.123
@payloadcms/plugin-search: 3.0.0-beta.123
@payloadcms/plugin-seo: 3.0.0-beta.123
@payloadcms/richtext-lexical: 3.0.0-beta.123
@payloadcms/translations: 3.0.0-beta.123
@payloadcms/ui/shared: 3.0.0-beta.123
react: 19.0.0-rc-65a56d0e-20241020
react-dom: 19.0.0-rc-65a56d0e-20241020
Operating System:
Platform: linux
Arch: x64
Version: #1 SMP Fri Mar 29 23:14:13 UTC 2024
Available memory (MB): 7866
Available CPU cores: 12
Yeah sorry @r1tsuu I don't believe there were any other steps necessary to reproduce this.
I have had the same issue. It is erroring out at the following stage of the seeding function:
// update each post with related posts await payload.update({ id: post1Doc.id, collection: 'posts', data: { relatedPosts: [post2Doc.id, post3Doc.id], }, req, }) ...
I wonder if it is trying to update the related posts data for each post, before it has actually finished populating each post, so it is requesting post1Doc.id, and that doesn't yet exist?
When I comment out the three related post updates in the seed function it completes the seeding successfully.
I'm also having some slowness issues on even my localhost, so i wonder whether the vercel postgres connection is slow and that is causing the issues.
This issue has been marked as stale due to lack of activity.
To keep this issue open, please indicate that it is still relevant in a comment below.
This issue was automatically closed due to lack of activity.
Hello.
I have a similar issue when seeding tables in Supabase.
[15:19:03] INFO: Seeding database...
[15:19:03] INFO: — Clearing media...
[15:19:03] INFO: — Clearing collections and globals...
[15:19:04] INFO: Revalidating header
[15:19:04] INFO: Revalidating footer
[15:19:06] INFO: — Seeding demo author and user...
[15:19:07] INFO: — Seeding media...
[15:19:10] INFO: — Seeding categories...
[15:19:16] INFO: — Seeding posts...
[15:19:16] INFO: Revalidating post at path: /posts/digital-horizons
[15:19:17] ERROR: insert or update on table "posts" violates foreign key constraint "posts_meta_image_id_media_id_fk"
GET /api/seed 500 in 14292ms
I tried manually changing the foreign key relation but somehow it did not work. Also tried removing table entries, but it seems to be very fragile, leading to even admin page to be unavailable. I had to reinitialize new database and Payload CMS projects.
Is there any command to clear the database with a command, without breaking the database?
Thanks.
I worked around this issue by disabling the images in the seed scripts, which helped seeding to complete without errors. Then, uploading assigning those images manually worked for me.
Hello.
I have a similar issue when seeding tables in Supabase.
[15:19:03] INFO: Seeding database... [15:19:03] INFO: — Clearing media... [15:19:03] INFO: — Clearing collections and globals... [15:19:04] INFO: Revalidating header [15:19:04] INFO: Revalidating footer [15:19:06] INFO: — Seeding demo author and user... [15:19:07] INFO: — Seeding media... [15:19:10] INFO: — Seeding categories... [15:19:16] INFO: — Seeding posts... [15:19:16] INFO: Revalidating post at path: /posts/digital-horizons [15:19:17] ERROR: insert or update on table "posts" violates foreign key constraint "posts_meta_image_id_media_id_fk" GET /api/seed 500 in 14292msI tried manually changing the foreign key relation but somehow it did not work. Also tried removing table entries, but it seems to be very fragile, leading to even admin page to be unavailable. I had to reinitialize new database and Payload CMS projects.
Is there any command to clear the database with a command, without breaking the database?
Thanks.
Closing as this issue hasnt been reproduced since - seed script has been changed
This issue has been automatically locked. Please open a new issue if this issue persists with any additional detail.