node.js - 我使用 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 已经存在
解决方案
推荐阅读
- javascript - 正则表达式仅修剪逗号,但不在文本之间和引用时修剪 - Java 脚本
- scala - 如何使此定期指标收集代码更具功能性(不可变状态)?
- excel - VBA Excel - 在 Outlook 邮件正文中粘贴图表(不是图像)
- java - 无法写入具有权限的 SD 卡
- java - Spring Data Rest:摘录为封闭投影
- html - 如何让我的 CSS Grid 布局响应式?
- c# - 在模拟另一个用户时请求 Kerberos 票证时,安全包中没有凭据
- r - ifelse 测试选择一个值而不是两个
- jquery - 在数据库中插入选中的复选框值并在未选中时将其删除
- angular - 茉莉花测试中是否可以获取模板引用变量?