Node.js:在Sequelize中定义Postgres模式 [英] Node.js: Defining Postgres Schemas in Sequelize

查看:231
本文介绍了Node.js:在Sequelize中定义Postgres模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

官方文档并未明确说明如何为数据库定义架构通过他们自己。我假设Sequelize与MySql的关系比Postgres(其中的模式是强制性的)更紧密。

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).

如果我已经在Postgres中创建了一些模式,该如何同步

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

推荐答案

您可以使用 model.schema ,例如:

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");

这篇关于Node.js:在Sequelize中定义Postgres模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆