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.

Primary key is not "id"

See original GitHub issue

I tried to declare the user table as:

table.increments('user_id').primary();
table.string('username');

but when I do a HTTP GET call to the server /user/1 I got the error

{
  "name": "BadRequest",
  "message": "select `user`.* from `user` where `id` = '1' - ER_BAD_FIELD_ERROR: Unknown column 'id' in 'where clause'",
  "code": 400,
  "className": "bad-request",
  "errors": {}
}

Expected result

the user record would be shown accordingly.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

9reactions
dafflcommented, Apr 27, 2017

If you want to use an id key that is not id you have to tell the adapter which id property to use when initializing the service as documented here.

app.use('/messages', service({
  id: 'user_id',
  Model: db,
  name: 'messages'
}));
0reactions
dafflcommented, May 9, 2017

Can you share a repository to reproduce the issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it ever a good idea to not have an 'id' primary key for a table?
Longer answer: if you have a table to be used in a many-to-many relationship, you don't really need a primary key. Then it...
Read more >
When your table's primary key is not called ID? - Laracasts
I'm trying to get laravel to play nicely with a legacy DB structure. Here is it: products products_id, products_name, products_price products_to_categories ...
Read more >
Add or change a table's primary key in Access
Often, a unique identification number, such as an ID number or a serial number or code, serves as a primary key in a...
Read more >
404 after create when primary key is not id · Issue #189 - GitHub
When creating a new resource, it tries to go to the view resource page by grabbing . id off the returned object. However,...
Read more >
ID Column if not Primary Key? - SQL Server Forum
Solution: If you have no other unique identifier in your table, then using an identity column as the primary/clustered key is fine.
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