[英]Sequelize not creating any tables in postgresql
I just pulled a project to a new machine, I use PostgreSQL for my DB, sequelize as an ORM, and feathersjs and express or middleware.我刚刚将一个项目拉到一台新机器上,我将 PostgreSQL 用于我的数据库,续集为 ORM,以及feathersjs 和 express 或中间件。 I try to start the project as I always do but it doesn't work.
我尝试像往常一样开始这个项目,但它不起作用。
I have an.env file with all my environment configuration info, what I usually do is first run sequelize db:create
, to create the DB, after that, I use npm start
to create the tables.我有一个包含所有环境配置信息的 .env 文件,我通常做的是首先运行
sequelize db:create
来创建数据库,之后,我使用npm start
创建表。 However when I do it it doesn't create any table or show any error, it just shows the info: Feathers application started on http://localhost:3030
but when I open pgAdmin the Database is empty.但是,当我这样做时,它不会创建任何表或显示任何错误,它只显示
info: Feathers application started on http://localhost:3030
但是当我打开 pgAdmin 时,数据库是空的。 I tried logging in in sequelize but it's not showing anything at all.我尝试登录sequelize,但它根本没有显示任何内容。 I also deleted the ENV and it doesn't show any error at
npm start
(it does show an error at sequelize db:create
. This is driving me nuts.我还删除了 ENV,它在
npm start
时没有显示任何错误(它在sequelize db:create
时确实显示错误。这让我发疯了。
Heres my sequelize.js:这是我的 sequelize.js:
require('dotenv').config();
const Sequelize = require('sequelize');
const { Op } = Sequelize;
const operatorsAliases = {
// ...
};
module.exports = function (app) {
const connectionString = `postgres://${process.env.DB_USERNAME}:${process.env.DB_PASSWORD}@` +
`${process.env.DB_HOST}:${process.env.DB_PORT}/${process.env.DB_NAME}`;
const sequelize = new Sequelize(connectionString, {
dialect: 'postgres',
dialectOptions: {
ssl: false
},
logging: console.log,
operatorsAliases,
define: {
freezeTableName: true
}
});
const oldSetup = app.setup;
app.set('sequelizeClient', sequelize);
app.setup = function (...args) {
const result = oldSetup.apply(this, args);
// Set up data relationships
const models = sequelize.models;
Object.keys(models).forEach(name => {
if ('associate' in models[name]) {
models[name].associate(models);
}
});
// Sync to the database
sequelize.sync({ logging: console.log });
return result;
};
};
My npm start script just points to an app.js file where I just import sequelize with app.configure(sequelize);
我的 npm 启动脚本只是指向一个 app.js 文件,我只是在其中使用
app.configure(sequelize);
You may need to run sequelize db:migrate
after creating the database您可能需要在创建数据库后运行
sequelize db:migrate
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.