Multi-tenant Demo and Postgres Issues

default discord avatar
w33ts
last month
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
    Payload Team
    last month

    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_oconnell
    4 weeks ago

    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
    Payload Team
    4 weeks ago

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

  • default discord avatar
    mangowi
    3 weeks ago

    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
    Payload Team
    3 weeks ago

    Any updates will be on the above links

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.