You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
After migration to a new project, querying relationships return error: "Could not find foreign keys between these entities. No relationship found between X and Y." #2200
Scenario: Using two projects (say: dev and staging). Both hosted by supabase. I'm migrating the schema like the recomendation, realtime disabled.
The issue: on dev environment, where I do everything by sql statements or interface I'm able to query relationships defined by foreign key. E.g.:
const{ data, error }=awaitsupabase.from<IYEntity>("X").select(`name, uuid, Y (key, is_valid)`).eq("uuid",id).limit(1);
When using the staging project, I get "Could not find foreign keys between these entities. No relationship found between X and Y." while running the same query. I reviewed both DBs and they appear to be identical. I dropped all tables on the staging environment and deleted on procedures. The migration runs, everything appears to be fine, but the query still throws the same error.
To Reproduce
Define a database with foreign key relationships. E.g.:
Migrate the DB to a new project.
Try a query like the one shown.
System information
OS: Linux.
Version of supabase-js: 1.15.1
Version of Node.js: v15.11.0
Additional context
The only think I can think is of restarting the postgrest container, I'd love to be able to do that from the supabase interface or any API. Is there such an option?
It's likely that when you did the migration, the event trigger that automatically reloaded postgrest metadata was lost. This can be checked with:
select evtname, evtevent from pg_event_trigger;
-- should show-- api_restart ddl_command_end
If the event trigger is not there, you can create it with:
CREATE OR REPLACEFUNCTIONextensions.notify_api_restart()
RETURNS event_trigger
LANGUAGE plpgsql
AS $$
BEGIN
NOTIFY ddl_command_end;
END;
$$;
CREATE EVENT TRIGGER api_restart ON ddl_command_end
EXECUTE PROCEDURE extensions.notify_api_restart();
COMMENT ON FUNCTION extensions.notify_api_restart IS 'Sends a notification to the API to restart. If your database schema has changed, this is required so that Supabase can rebuild the relationships.';
ERROR: permission denied to create event trigger "api_restart"
HINT: Must be superuser to create an event trigger.
ERROR: must be owner of event trigger api_restart
I'll modify my migration script to run this after the schema is copied.
Activity
steve-chavez commentedon Jul 4, 2021
Hey @EdgarBarrantes,
Try running this SQL and retry the postgrest-js request:
-- manually refresh postgrest foreign key metadata NOTIFY ddl_command_end;It's likely that when you did the migration, the event trigger that automatically reloaded postgrest metadata was lost. This can be checked with:
If the event trigger is not there, you can create it with:
Related to #1416 (comment)
EdgarBarrantes commentedon Jul 4, 2021
Brilliant! Yeah that was it.
Justed the migration again and indeed:
I'll modify my migration script to run this after the schema is copied.
Thank you so much!
feat: update @supabase/*-js libraries to v2.102.1 (#44623)