I have created migration file and its seeder file for the table. Now when I try to execute the seeder command it is throwing error of "Unknown column in 'field list'"
I have recreated these many times, I don't know why I am getting this! May be some minor mistake I have made.
Here is my migration file:
'use strict';
/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable('subscriptions', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
subscriptionPlanType: {
type: Sequelize.STRING
},
name: {
type: Sequelize.STRING
},
memberCount: {
type: Sequelize.INTEGER
},
amount: {
type: Sequelize.FLOAT
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
async down(queryInterface, Sequelize) {
await queryInterface.dropTable('subscriptions');
}
};
and here is the seeder file:
"use strict";
/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
/**
* Add seed commands here.
*
* Example:
* await queryInterface.bulkInsert('People', [{
* name: 'John Doe',
* isBetaMember: false
* }], {});
*/
return queryInterface.bulkInsert("Users", [
{
subscriptionPlanType: "Monthly",
name: "Tset1",
memberCount: 15,
amount: 65.99,
createdAt: "Oct 17 2022 22:34:39",
updatedAt: "Oct 17 2022 22:34:39",
},
{
subscriptionPlanType: "Yearly",
name: "Test2",
memberCount: 25,
amount: 105.99,
createdAt: "Oct 17 2022 22:34:39",
updatedAt: "Oct 17 2022 22:34:39",
},
]);
},
async down(queryInterface, Sequelize) {
/**
* Add commands to revert seed here.
*
* Example:
* await queryInterface.bulkDelete('People', null, {});
*/
},
};
And I am getting the error while executing this command: npx sequelize-cli db:seed:all
Unknown column 'subscriptionPlanType' in 'field list'
How can I get rid of this error?
You made a mistake either in the migration or in the seeder. The table names are not the same. In the migrations, the table name is subscriptions
and in the seeder it is Users