question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SQL error: 'column reference "id" is ambiguous'

See original GitHub issue

I’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:closed
  • Created 8 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
alepncommented, Jun 19, 2015

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.

0reactions
alepncommented, Jun 22, 2015

I opened a new issue. The problem is get the correct pk_name on subclasses. Take a look #447.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found