SQL error: 'column reference "id" is ambiguous'
See original GitHub issueI’ll look into this tomorrow but since the update to 2.2.0 I’ve noticed this issue on sentry;
ProgrammingError at /app/model/1/
column reference "id" is ambiguous
LINE 1: SELECT (CASE WHEN id='1' THEN 0 END) AS "ordering", "...
It complains about validate_values(), as I said I’ll update this ticket later, but it occurs when saving inlines that have autocomplete fields
Issue Analytics
- State:
- Created 8 years ago
- Comments:12 (7 by maintainers)
Top Results From Across the Web
How to Solve the “Ambiguous Name Column” Error in SQL
One of the simplest ways to solve an “ambiguous name column” error — without changing column name — is to give the tables...
Read more >SQL column reference "id" is ambiguous - Stack Overflow
This issue actually happens when there is same column name in both tables. where <tableName.columnName> = <value> can solve this issue. – Shah...
Read more >U122: Column reference is ambiguous - pganalyze
Explanation: This error occurs when the referenced column can't be resolved unambiguously. This may occur when you have two tables that have columns...
Read more >What does the SQL 'ambiguous column name' error mean?
Ambiguous error means that you are calling a certain field in which exist in both Table and the SQL has no idea where...
Read more >'Column reference is ambiguous' when upserting element into ...
I tried to use this query, but when I run it, it errors with Column reference 'affiliate_code' is ambiguous : INSERT INTO accounts...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi, the bug ‘column reference “id” is ambiguous’ is resolved. But now we have a new problem when pk name is different from default (id) and the autocomplete field is a foreign key.
The problem is in "SELECT (CASE WHEN the_pk_name=‘877’ THEN 0 END) AS “ordering”, “autht…”.
So I changed the code in models.py FROM:
pk_name = (‘id’ if not getattr(choices.model._meta, ‘pk’, None) else choices.model._meta.pk.name) pk_name = ‘%s.%s’ % (choices.model._meta.db_table, pk_name)
TO:
pk_name = (‘id’ if not getattr(choices.model._meta, ‘pk’, None) else choices.model._meta.pk.attname) pk_name = ‘%s.%s’ % (choices.model._meta.db_table, pk_name)
Then change pk.name to pk.attname it works to me. I think the solution is get the field name in table directly.
I opened a new issue. The problem is get the correct pk_name on subclasses. Take a look #447.