'What is wrong with how I'm seeding data in my db using Sequelizer for React Native App

I'm a newbie in sequelizer. I've been trying to seed data to table but failed to do so for some errors I don't get.

Here are the tables I'm working with.

const User = sequelize.define('user', {
   id: {
      type: Sequelize.INTEGER,
      autoIncrement: true,
      allowNull: false,
      primaryKey: true,
   },
   name: {
      type: Sequelize.STRING,
   },
   password: {
      type: Sequelize.STRING,
      allowNull: false,
   },
   phone_number: {
      type: Sequelize.STRING,
      allowNull: false,
   },
},
   { timestamps: false }
);

const Profile = sequelize.define('profile', {
   id: {
       type: Sequelize.INTEGER,
       autoIncrement: true,
       allowNull: false,
       primaryKey: true,
    },
    name:{
       type: Sequelize.STRING,
    },
    age: {
       type: Sequelize.INTEGER,
       allowNull: false,
    },
    school: {
       type: Sequelize.STRING,
       allowNull: true,
    },
    introduction: {
       type: Sequelize.STRING,
    },
    UserId:{
       type: Sequelize.INTEGER,
       references:{
          model : User,
          key : "id"
       }
    }
   },
   { timestamps : false }        
);

User.hasMany(Profile, {
   foreignKey : 'UserId',
   allowNull: false,
   constraints : true,
   onDelete : 'cascade'
});
Profile.belongsTo(User, {
   foreignKey : 'UserId'
});

As you can see here, User and Profile has one to many relationship.

Now I'm seeding a data like this:

Profile.create({
   id:1,
   name: "Taki",
   age: 31,
   school: "Hogwarts",
   introduction: "Manager",
   User : [
      {id:2, name: "HyunJune", password: "password", phone_number: "01000000000"},
      {id:3, name: "DooYong", password: "password", phone_number: "01000000001"}, 
   ]
   },
   {
      include: [User]
});

And this is the Error Message I'm getting.

Executing (default): CREATE TABLE IF NOT EXISTS `users` (`id` INTEGER NOT NULL auto_increment , `name` VARCHAR(255), `password` VARCHAR(255) NOT NULL, `phone_number` VARCHAR(255) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB;
Executing (default): INSERT INTO `profiles` (`id`,`name`,`age`,`school`,`introduction`) VALUES (?,?,?,?,?);
node:internal/process/promises:265
            triggerUncaughtException(err, true /* fromPromise */);
            ^

Error
    at Query.run (C:\Projects\Playground\src\server\node_modules\sequelize\dist\lib\dialects\mysql\query.js:52:25)
    at C:\Projects\Playground\src\server\node_modules\sequelize\dist\lib\sequelize.js:313:28
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async MySQLQueryInterface.insert (C:\Projects\Playground\src\server\node_modules\sequelize\dist\lib\dialects\abstract\query-interface.js:297:21)
    at async model.save (C:\Projects\Playground\src\server\node_modules\sequelize\dist\lib\model.js:2417:35)
    at async Function.create (C:\Projects\Playground\src\server\node_modules\sequelize\dist\lib\model.js:1329:12) {
  name: 'SequelizeDatabaseError',
  parent: Error: Unknown column 'name' in 'field list'
      at Packet.asError (C:\Projects\Playground\src\server\node_modules\mysql2\lib\packets\packet.js:728:17)
      at Prepare.execute (C:\Projects\Playground\src\server\node_modules\mysql2\lib\commands\command.js:29:26)
      at Connection.handlePacket (C:\Projects\Playground\src\server\node_modules\mysql2\lib\connection.js:456:32)
      at PacketParser.onPacket (C:\Projects\Playground\src\server\node_modules\mysql2\lib\connection.js:85:12)
      at PacketParser.executeStart (C:\Projects\Playground\src\server\node_modules\mysql2\lib\packet_parser.js:75:16)
      at Socket.<anonymous> (C:\Projects\Playground\src\server\node_modules\mysql2\lib\connection.js:92:25)
      at Socket.emit (node:events:520:28)
      at addChunk (node:internal/streams/readable:315:12)
      at readableAddChunk (node:internal/streams/readable:289:9)
      at Socket.Readable.push (node:internal/streams/readable:228:10) {
    code: 'ER_BAD_FIELD_ERROR',
    errno: 1054,
    sqlState: '42S22',
    sqlMessage: "Unknown column 'name' in 'field list'",
    sql: 'INSERT INTO `profiles` (`id`,`name`,`age`,`school`,`introduction`) VALUES (?,?,?,?,?);',
    parameters: [ 1, 'Taki', 31, 'Hogwarts', 'Manager' ]
  },
  original: Error: Unknown column 'name' in 'field list'
      at Packet.asError (C:\Projects\Playground\src\server\node_modules\mysql2\lib\packets\packet.js:728:17)
      at Prepare.execute (C:\Projects\Playground\src\server\node_modules\mysql2\lib\commands\command.js:29:26)
      at Connection.handlePacket (C:\Projects\Playground\src\server\node_modules\mysql2\lib\connection.js:456:32)
      at PacketParser.onPacket (C:\Projects\Playground\src\server\node_modules\mysql2\lib\connection.js:85:12)
      at PacketParser.executeStart (C:\Projects\Playground\src\server\node_modules\mysql2\lib\packet_parser.js:75:16)
      at Socket.<anonymous> (C:\Projects\Playground\src\server\node_modules\mysql2\lib\connection.js:92:25)
      at Socket.emit (node:events:520:28)
      at addChunk (node:internal/streams/readable:315:12)
      at readableAddChunk (node:internal/streams/readable:289:9)
      at Socket.Readable.push (node:internal/streams/readable:228:10) {
    code: 'ER_BAD_FIELD_ERROR',
    errno: 1054,
    sqlState: '42S22',
    sqlMessage: "Unknown column 'name' in 'field list'",
    sql: 'INSERT INTO `profiles` (`id`,`name`,`age`,`school`,`introduction`) VALUES (?,?,?,?,?);',
    parameters: [ 1, 'Taki', 31, 'Hogwarts', 'Manager' ]
  },
  sql: 'INSERT INTO `profiles` (`id`,`name`,`age`,`school`,`introduction`) VALUES (?,?,?,?,?);',
  parameters: [ 1, 'Taki', 31, 'Hogwarts', 'Manager' ]
}

I don't get this message since I've clearly included 'name' in the datafield for both tables.

Can someone identify what I'm doing wrong?

Thanks a lot in advance :)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source