I want check a table and if table is empty create a record.
my code:
module.exports = (sequelize, DataTypes) => {
const About = sequelize.define("About",
{
id: {
type: DataTypes.BIGINT,
autoIncrement: true,
allowNull: false,
primaryKey: true,
},
title: DataTypes.STRING(150),
content: DataTypes.TEXT("medium"),
},
{
freezeTableName: true,
timestamps: false,
},
);
About.findAll()
.then(about => {
if (about.length === 0) {
About.create({
title: "About Us",
content: "Lorem ipsum dolor sit amet...",
});
}
});
return About;
};
But when table doesn't exist I get this error:
Executing (default): SELECT
id
,title
,content
FROMAbout
ASAbout
;Unhandled rejection SequelizeDatabaseError: Table 'mydb.about' doesn't exist
how can I handle this issue?