0

I have everything installed on my computer, but still I got these errors:

Unhandled rejection SequelizeDatabaseError: SQLITE_ERROR: table Users has no column named last_name at Query.formatError (/Users/kamran/developer/WEB/WebCourse/p3/node_modules/sequelize/lib/dialects/sqlite/query.js:242:14) at /Users/kamran/developer/WEB/WebCourse/p3/node_modules/sequelize/lib/dialects/sqlite/query.js:47:29 at Statement.errBack (/Users/kamran/developer/WEB/WebCourse/p3/node_modules/sqlite3/lib/sqlite3.js:16:21)

here is my code:

'use strict';
module.exports = function(sequelize, DataTypes) {
  var User = sequelize.define('User', {
    first_name: DataTypes.STRING,
    last_name: DataTypes.STRING,
    username: DataTypes.STRING,
    password: DataTypes.STRING,
    photo_base64: DataTypes.STRING
  }, {
    classMethods: {
      associate: function(models) {
        // associations can be defined here
      }
    }
  });
  return User;
};

an here is my model:

var user = models.User.build({
            first_name:first_name,
            last_name:last_name,
            username:username,
            password:password,
            photo_base64:photo_base64
        });
        user.save().then(function(user) {
            console.log(user.get('username'));
        });
michelem
  • 14,430
  • 5
  • 50
  • 66
  • what is the schema of the User table of the underlying sqlite database ? – Jerome WAGNER Jul 05 '15 at 08:45
  • It seems your SQLite table hasn't `last_name` field – michelem Jul 05 '15 at 08:48
  • as you see there is last_name field in my models: first_name: DataTypes.STRING, last_name: DataTypes.STRING, – Kamran koupaee Jul 05 '15 at 08:50
  • @JeromeWAGNER : what do you mean by schema?? – Kamran koupaee Jul 05 '15 at 08:52
  • should sequelize autonomously create a sqlite User table or do you have to create it by hand ? it seems like the sqlite table is either not created or created with the wrong set of fields if you created it previously without upgrading the schema – Jerome WAGNER Jul 05 '15 at 09:36
  • 2
    Use sync() method to create a table – Sathish Jul 05 '15 at 14:01
  • Was last_name a column that didn't exist when the table was created? If so, this is why you should use migrations. If this is the case, either create a migration for the change to this table, else, as Sathish said, use sync() – swifty Jul 06 '15 at 12:37
  • You can find this answer helpful: [This can happen when you are trying to insert the data into the table where the column name does not exist or maybe schema that you are trying to insert into has been changed with the latest sequelize.js code.](https://stackoverflow.com/a/57294234/3202440) – kavigun Jul 31 '19 at 15:34

0 Answers0