首页 > 解决方案 > 我使用 force:false 如果表已经存在或者我创建 sequilize 现在如何

问题描述

const { Sequelize } = require('sequelize');
const sequelize = new Sequelize('test', 'root', '1234', {
host: 'localhost',
dialect: 'mysql',
});

const Postagem = sequelize.define('posts', {
titulos: {
type: Sequelize.STRING,
},
conteudo: {
type: Sequelize.TEXT,
},
});
//force true drop if alread exist
Postagem.sync({ force: false })
.then(function () {
// Table created

如果我现在可以使用一些参数或其他东西,我现在不知道是否创建或不

console.log('Connection has been established successfully!');
// return true;
})
.catch((err) => {
console.log('error' + err);
});

这在 mysql 中工作得很好,但我现在想如果创建 ou 已经存在

标签: node.jssequelize.jscreate-table

解决方案


推荐阅读