Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Multi-tenant Demo and Postgres Issues

default discord avatar
w33t.iolast year
6

Hello!



I ran into an issue deploying the multi-tenant demo. The database seeding throws the error "error: insert or update on table "users_tenants_roles" violates foreign key constraint "users_tenants_roles_parent_id_users_tenants_id_fk"" on both Neon and Supabase.



I did a bit of digging and figured out that I could run the migrate command, which successfully pushed up to both Neon and Supabase. I disabled the payload seed and DB drop in the .env and everything loaded fine. I tried it again with the payload seed enabled, which at least seeded the super user and a couple of tenants.



While doing some digging, I did come across this and applied the workaround, so I do not know if that's needed as well for this workaround. If required, I can revert the changes and give it a shot.

https://github.com/drizzle-team/drizzle-orm/issues/636

I did reference this as well, but I am on the latest version of the postgresql connector.

https://github.com/payloadcms/payload/issues/3568

Is it something to do with the seed.ts in the example?



Thank you!

  • discord user avatar
    denolfe
    last year

    We have been doing some work today getting the seeding working properly with Postgres. The latest updates to the templates may resolve your issues.

  • default discord avatar
    tim_oconnelllast year

    I don't think is to do with the seed process - the same error is thrown when you manually add a tenant to a user in the UI and set their tenant role. It seems like it's adding the users_tenants_roles before the users_tenants



    Something that could be useful is to be able to turn on the drizzle logging so we can see the SQL queries that are being send to the db

  • discord user avatar
    denolfe
    last year

    Can you open an issue for the first item, and a github discussion feature request for the second?

  • default discord avatar
    mangowi_last year

    Hello, any news on this?


    ps - I think the issue happens too when you are creating a relationship between user and tenant using pg as database.

  • discord user avatar
    denolfe
    last year

    Any updates will be on the above links

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.