Node.js: Defining Postgres Schemas in Sequelize

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-12 06:15:46

问题


The Official Documentation doesn't explains clearly how define schemas for database by themselves. I'm assuming that Sequelize is more related to MySql than Postgres (where schemas are mandatory).

If I've already created some schemas in Postgres, how I could sync them with Sequelize?


回答1:


You can set the model with the schema using model.schema, something like:

var City = sequelize.define('City', {
    id: {
        type: sequelize.Sequelize.INTEGER,
        primaryKey: true,
        autoIncrement: true,
        field: 'id'
    },
    name: {
        type: sequelize.Sequelize.STRING,
        field: 'name'   
    }
  }, {
    timestamps: false,
    tableName: 'cities'
    });
City.schema("public");


来源:https://stackoverflow.com/questions/39580973/node-js-defining-postgres-schemas-in-sequelize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!