title: foreign key constraint for multi tenant users
body: <p>Thanks to @Peppermintology I was able to split my Laravel project into multiple tenants with separate databases for each. (I am using Tenancy for Laravel &amp; Passport for authentication)</p>
  <p>I would like the users to be global thought, one login and then you can switch between tenants.</p>
  <p>I came up with the following setup (simplified)</p>
  <p><code>user:</code></p>
  <ul>
  <li><code>user_id</code></li>
  <li><code>tenant_id</code></li>
  </ul>
  <p><code>tenant:</code></p>
  <ul>
  <li><code>tenant_id</code></li>
  </ul>
  <p><code>tenant_user:</code></p>
  <ul>
  <li><code>tenant_id</code></li>
  <li><code>user_id</code></li>
  <li><code>role_id</code></li>
  </ul>
  <p>All of these tables are on the central/global database &amp; foreign keys work just fine.</p>
  <p>Now since the application has a lot of user-specific data inside each tenant, and a user can have different personal data on different tenants I wanted to add a <code>user_id</code> to most fields on the tenant tables.</p>
  <p>i.e. <code>songs:</code></p>
  <ul>
  <li><code>user_id</code></li>
  <li><code>name</code></li>
  </ul>
  <p>Here the foreign key constraint doesn't work, as the user_id would be in the central database, but the songs table is in the current tenant database.</p>
  <p>I saw that there is passport support to enable passport in both central &amp; tenant domains (<a href="https://tenancyforlaravel.com/docs/v3/integrations/passport" rel="nofollow noreferrer">https://tenancyforlaravel.com/docs/v3/integrations/passport</a>), but this does not answer the foreign key question.</p>
  <p>What I'm wondering is if there is a common/smart way of solving this &amp; I would appreciate any suggestions.</p>