Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Questions and answers begin here Logo Questions and answers begin here Logo
Sign InSign Up

Questions and answers begin here

Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Blog
  • Contact Us

ER_BAD_FIELD_ERROR: Unknown column ‘id’ in ‘field list’ Sequelize with NodeJS

Home/ Questions/Q 245
Next
Answered
ER_BAD_FIELD_ERROR: Unknown column 'id' in 'field list' Sequelize with NodeJS
geniss.tha.menace
geniss.tha.menace Teacher

I have been struggling with a Sequelize error when running my Node.js application. The error message reads “ER_BAD_FIELD_ERROR: Unknown column ‘id’ in field list”. I am not sure what is causing this error and how to resolve it.
I have checked my database schema and double-checked my Sequelize model definitions to ensure that the ‘id’ field exists. I have also tried removing the field/column references from my code to see if that resolves the issue, but I continue to receive the same error.
Here is a sample of the code that I am using:
“`javascript
const Sequelize = require(‘sequelize’);
const sequelize = new Sequelize(‘database’, ‘username’, ‘password’, {
host: ‘localhost’,
dialect: ‘mysql’
});
const User = sequelize.define(‘user’, {
firstName: Sequelize.STRING,
lastName: Sequelize.STRING,
email: Sequelize.STRING,
});
sequelize.sync({ force: true })
.then(() => {
console.log(‘Database & tables created!’);
});
“`
Can anyone help me understand why I am receiving this error and how to resolve it? Thank you in advance for your assistance.

database connectivityerror handlingNode.jssequelize
  • 357
  • 0 Followers
  • 1
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

2 Answers

  • Voted
  • Oldest
  • Recent
  • Random
  1. Best Answer
    quirkygameplay Begginer
    2017-04-24T05:26:35+00:00Added an answer about 6 years ago

    Hey there,
    It seems that you are encountering the common “ER_BAD_FIELD_ERROR: Unknown column” error message on your Sequelize with Node.js. This error typically occurs when you try to access a database column that does not exist in your table.
    To fix this issue, you should first ensure that your database table has the correct columns defined. Double-check the spelling of your column names and make sure that they match the name you are querying in your Sequelize query. You may want to consider running a SELECT * query to view all of your table columns and verify that they match your expectations.
    If your column names are correct, the issue may be related to your model definitions. Make sure that your model definitions match your database schema. Check for any typos or misnamed columns, as well as any missing columns that may be causing the issue.
    Another possible solution is to update your Sequelize version. Some older versions of Sequelize have known issues related to column names and queries, so updating to a newer version may help to resolve the issue.

    In addition to these solutions, you may also want to check your query syntax. Ensure that your query is properly constructed and that all of your variables are correctly defined. You may want to consider running your query manually on your local database to ensure that it is functioning as expected.

    In summary, the “ER_BAD_FIELD_ERROR: Unknown column” error message can be resolved by checking your database table, model definitions, query syntax, and updating to the latest version of Sequelize. I hope this helps you to resolve the issue, and let me know if you run into any further problems or have any questions!

    • 56
    • Reply
    • Share
      Share
      • Share onFacebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  2. heng0301 Begginer
    2017-04-30T20:48:30+00:00Added an answer about 6 years ago

    To resolve the error “Bad field error: Unknown column ‘id’ in ‘field list'”, you can try making changes in the table definition. Check if the table definition and the model definition is in sync, and the name of the table and columns match with the REST endpoint that is being created. Additionally, you can also look into the definition of the association, and use the foreign key property to create the association properly.

    Another possible cause for this error is using a different column name in the database table or changing the column definition. Make sure that the correct column name is being used in the query. Double-check the query that is creating the table and make sure that there are no spelling errors on column/field names. Similarly, when updating column/field names or definitions, ensure that you are updating the queries that use those as well.

    It is important to test the application thoroughly after making these changes to ensure that they have resolved the issue. By being patient and thorough in your approach, you will be able to identify and fix the issue without much difficulty.

    • 44
    • Reply
    • Share
      Share
      • Share onFacebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.