我面临着从远程服务器获取数据的问题。我正在使用Sequelize ORM与具有--read-only选项的远程数据库进行通信。我不想在此服务器上创建,添加或删除任何数据库或表,我只需要从该服务器获取数据即可。这就是为什么我使用sequelize.sync()连接到数据库时添加了选项的原因
const express = require('express');
const ISOMessageModel = require('../../models/v1/incognito/iSOMessagesModel');
const router = express.Router();
var Sequelize = require('sequelize');
const testCheck = (req, res, next) => {
console.log('In incognito controller');
const sequelize = new Sequelize('db', 'user', 'password', {
host: 'host',
port: 3306,
dialect: 'mysql',
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
},
});
sequelize
.authenticate()
.then(() => {
console.log('Connection has been established successfully.');
})
.catch(err => {
console.error('Unable to connect to the database:', err);
});
const objectModel = sequelize.define('ISOMessages',ISOMessageModel);
主机是正确的,例如,它刚刚被编辑过。 模型看起来像这样:
var Sequelize = require('sequelize');
const ISOMessageModel = {
id: {
type: Sequelize.STRING,
unique: true,
primaryKey: true,
allowNull: false
},
message: {
type: Sequelize.TEXT,
allowNull: false
},
status: {
type: Sequelize.ENUM,
values: ['SUCCESS', 'FAILED']
},
provider: {
type: Sequelize.ENUM,
values: ['UFC', 'GC']
},
singularResponse: {
type: Sequelize.TEXT
},
userId: {
type: Sequelize.INTEGER
},
cardId: {
type: Sequelize.STRING
},
amount: {
type: Sequelize.INTEGER
},
commission: {
type: Sequelize.INTEGER
},
location: {
type: Sequelize.TEXT
}
}
module.exports = ISOMessageModel;
我正在将Sequelize与选项同步:
{力:假,变更:假}
sequelize.sync({force: false, alter : false }).then(() => {
console.log('Do query from objectModel');
}).catch(function(err) {
console.log(err, "Something went wrong with the Database Update!")
});
错误:错误:MariaDB服务器正在使用--read-only选项运行,因此它无法执行此语句。 我经过研究发现,在同步过程中{force:false,alter:false}一定不能写入或更新数据,因此无法理解为什么我收到此错误。
思想。