payload icon indicating copy to clipboard operation
payload copied to clipboard

PostgreSQL 18 does not work

Open Arecsu opened this issue 1 year ago • 15 comments

Describe the Bug

PostgreSQL 18 is buggy with PayloadCMS 3.57.0. It has been released a few days ago if I'm not mistaken. The solution is to use PostgreSQL 17, at least in my case. So maybe the docker-compose.yml from the examples or the docs should be wary of this. I don't know if this is something that can be fixed in PayloadCMS.

Just informing this because I went almost crazy all day trying to figure out the source of this error, and it was the latest version of PostgreSQL all along, seems to introduce breaking changes

✓ Compiled / in 1128ms (758 modules)
[✓] Pulling schema from database...
 ⨯ Error: Failed query: ALTER TABLE "payload_preferences_rels" DROP CONSTRAINT "payload_preferences_rels_id_not_null";
params:
    at async HomePage (src/app/(frontend)/page.tsx:13:18)
  11 |   const headers = await getHeaders()
  12 |   const payloadConfig = await config
> 13 |   const payload = await getPayload({ config: payloadConfig })
     |                  ^
  14 |   const { user } = await payload.auth({ headers })
  15 |
  16 |   const fileURL = `vscode://file/${fileURLToPath(import.meta.url)}` {
  query: 'ALTER TABLE "payload_preferences_rels" DROP CONSTRAINT "payload_preferences_rels_id_not_null";',
  params: [],
  payloadInitError: true,
  digest: '4011555175',
  [cause]: error: column "id" is in a primary key

Link to the code that reproduces this issue

Reproduction Steps

Steps:

  1. Start a new PayloadCMS project with a basic template.
  2. Deploy a new database with PostgreSQL 18 (using image: postgres:latest in docker-compose.yml)
  3. Configure PayloadCMS to use this database
  4. Get the database running
  5. pnpm run dev to open PayloadCMS
  6. Try to add a simple text field to any of the default collections
  7. Errors such as "ALTER TABLE .... DROP CONSTRAINT" and "column "id" is in a primary key" all over the place with Drizzle. Manual migrations work good.

Which area(s) are affected? (Select all that apply)

db-postgres

Environment Info

Postgres 18.0

Binaries:
  Node: 24.8.0
  npm: N/A
  Yarn: N/A
  pnpm: 10.13.1
Relevant Packages:
  payload: 3.57.0
  next: 15.4.4
  @payloadcms/db-postgres: 3.57.0
  @payloadcms/email-nodemailer: 3.57.0
  @payloadcms/graphql: 3.57.0
  @payloadcms/next/utilities: 3.57.0
  @payloadcms/payload-cloud: 3.57.0
  @payloadcms/richtext-lexical: 3.57.0
  @payloadcms/translations: 3.57.0
  @payloadcms/ui/shared: 3.57.0
  react: 19.1.0
  react-dom: 19.1.0
Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Tue, 23 Sep 2025 13:40:26 +0000
  Available memory (MB): 32015
  Available CPU cores: 16

Arecsu avatar Sep 29 '25 18:09 Arecsu

Please add a reproduction in order for us to be able to investigate.

Depending on the quality of reproduction steps, this issue may be closed if no reproduction is provided.

Why was this issue marked with the invalid-reproduction label?

To be able to investigate, we need access to a reproduction to identify what triggered the issue. We prefer a link to a public GitHub repository created with create-payload-app@latest -t blank or a forked/branched version of this repository with tests added (more info in the reproduction-guide).

To make sure the issue is resolved as quickly as possible, please make sure that the reproduction is as minimal as possible. This means that you should remove unnecessary code, files, and dependencies that do not contribute to the issue. Ensure your reproduction does not depend on secrets, 3rd party registries, private dependencies, or any other data that cannot be made public. Avoid a reproduction including a whole monorepo (unless relevant to the issue). The easier it is to reproduce the issue, the quicker we can help.

Please test your reproduction against the latest version of Payload to make sure your issue has not already been fixed.

I added a link, why was it still marked?

Ensure the link is pointing to a codebase that is accessible (e.g. not a private repository). "example.com", "n/a", "will add later", etc. are not acceptable links -- we need to see a public codebase. See the above section for accepted links.

Useful Resources

github-actions[bot] avatar Sep 29 '25 18:09 github-actions[bot]

Relevant: https://discord.com/channels/1043890932593987624/1421836581433770036

AlessioGr avatar Sep 29 '25 21:09 AlessioGr

Same issue here, new to payloadcms, but this was killer, we needed to reset the database between nearly all changes. Thanks for the heads up, reverting to postgres 17 fixed the issue for us.

jedashford avatar Oct 01 '25 19:10 jedashford

This is a killer problem, also cannot develop on 18 and had to drop to 17.

ghost avatar Oct 09 '25 00:10 ghost

Can confirm downgrade PG to v17 solved the issue.

kchaengsiri avatar Oct 10 '25 09:10 kchaengsiri

Phew thought I was going crazy there, yes downgrading to 17 solved breaking between every schema change

benjaminben avatar Oct 24 '25 23:10 benjaminben

Phew thought I was going crazy there, yes downgrading to 17 solved breaking between every schema change

I actually ended up being crazy in the process my brother 🤣, so in order to avoid other people to go through hell like I did, I created this issue.

Speaking of which, I find interesting that PayloadCMS didn't enforce postgre 17 at least for create-payload-cms, which is the one I've used to learn and deploy Payload a month ago. New users must be growing white hair.

edit: seems that a pull request has been submitted https://github.com/payloadcms/payload/pull/14332

Arecsu avatar Oct 25 '25 00:10 Arecsu

Yes it was also painful for me. Props to @Arecsu for giving visibility to the issue and providing a solution.

It appears when this was introduced, Postgres16 was the :latest and the auto upgrade Postgres17 didn't seem to be an issue. Hindsight shows this should have been pinned from the get go.

Things to do now probably

  • [ ] Check if there other images pinned to :latest that could at any moment break some setups? Mongodb's image is also pinned to :latest.
  • [ ] Add notices that there are issues with Postgres18 to the storage adapter's README file and the Postgres doc page.

Note: Searching for :latest in the codebase I found this reference to a "Custom postgres 17 docker image" I will have a look at it

romainpi avatar Oct 25 '25 04:10 romainpi

Here is:

romainpi avatar Oct 25 '25 05:10 romainpi

Thank you, thank you very much @Arecsu! I had been searching for this problem for days, and I was like, how can a freshly created project get a runtime error on startup. Jeez!

li-zck avatar Nov 07 '25 08:11 li-zck

The related drizzle-kit issue was fixed in [email protected], so as soon payload updates to that version, Postgres 18 can be used.

EasySouls avatar Nov 15 '25 22:11 EasySouls

Yes, can confirm [email protected] issue is fixed.

marsender avatar Nov 16 '25 13:11 marsender

If you guys blocked to proceed with development, override from your package.json as this for time being

{ "overrides": { "drizzle-kit": "0.31.7" } }

nrooban avatar Nov 20 '25 10:11 nrooban

🚀 This is included in version v3.65.0

github-actions[bot] avatar Nov 25 '25 18:11 github-actions[bot]

This issue has been automatically locked. Please open a new issue if this issue persists with any additional detail.

github-actions[bot] avatar Dec 03 '25 05:12 github-actions[bot]