Guys I need some help I am creating a basic table ...
# help
s
Guys I need some help I am creating a basic table with a foreign key to another table's id, but I get an error which really does not tell much
Copy code
invalid query
How can I debug something like this?
s
Can you provide the code that you are trying to run that's causing this error? You can debug something like this by making sure you are using correct SQL query syntaxes.
s
I basically created a
gag_visibility
table with an id and a title
and now I want to create a gags table and use
gag_visibility
inside that
ohh
wait
gag_visibility_id
should not be a foreign key right?
oh no it should be a foreign key
nvm
s
Is the type correct? is that column a
int8
in the
gag_visibility
table?
s
let me check
yes its an int8
s
Ok let me test this in one of my project's
s
thanks
s
Just tested it and it worked
s
xD
dang
s
Yeah not sure why it isn't working for you
Maybe try deleting the gag_visibility table and creating it again
s
yep going to try that
ok it works now strange
but good to know that something like this can solve some issues 😄
thanks 🙏
g
I got that error once when the link column name was the same as the reference table column (like id and id), or it was random. Changing the name of the link column fixed it.
@User OK... I did a quick test... strange result. If you forget the table name filed at top, generate a link and save you get a warning on no table name. fix the name and save you get the query error. Exact same table (default actually) and enter table name first, do you link to another table and good to go on save... Could it be the UI is formatting the link SQL code without the main table name when you do the link part (so it has no name) when you go to save?
after forgetting the top table field name, setting up a link , then fixing the title field.
s
Ok cool I am able to replicate this too. If one of you can log this as a bug on the supabase/supabase GitHub issue tracker along with the steps to replicate we can have someone look into it.
@User you are correct in that its saving the first query where the table doesn't have a name and then later when you fill in the name it's sending the first query along with another query with the name First Query
Copy code
json
{"query":"ALTER TABLE \"public\".\"\" ADD CONSTRAINT \"_gig_visibility_id_fkey\" FOREIGN KEY (\"gig_visibility_id\") REFERENCES \"public\".\"gag_visibility\" (\"id\");"}
Other Query
Copy code
json
{"query":"ALTER TABLE \"public\".\"gaga\" ADD PRIMARY KEY (\"id\")"}
g
They like my bug reports, I'll write it up unless @User jumps in before morning...
s
@User its fine you can write the bug / issue 😄 Cool thing that we found something which can be improved 🙂
g
https://github.com/supabase/supabase/issues/5429 Note the error occurs even without the save missing name error, basically if you don't have a table name, the intermediate steps are formatted wrong, then even filling in table name before the save does no good.