从mysql迁移后,postgres数据库不能正常工作

Mak*_*mat 3 mysql postgresql sequelize.js postgresql-9.3

我在sequelize中将MySQL数据库更改为postgreSQL.但是在迁移之后我在表或模型中出现了大写和小写的第一个字母...在我的MySQL版本正常工作之前但是在迁移之后我得到了错误消息: 500 SequelizeDatabaseError: relation "Users" does not exist

我的用户型号:

module.exports = function(sequelize, Sequelize) {
  var User = sequelize.define("User", {
    // profile
    userlevel: Sequelize.STRING,
    restaurant: Sequelize.STRING,
    access: Sequelize.STRING,
    optionsid: Sequelize.STRING,
    email: Sequelize.STRING,
    name: Sequelize.STRING,
    gender: Sequelize.STRING,
    location: Sequelize.STRING,
    website: Sequelize.STRING,
    picture: Sequelize.STRING,
    // Oauth
    password: {
      type: Sequelize.STRING,
      set: function(v) {
        var salt = bcrypt.genSaltSync(5);
        var password = bcrypt.hashSync(v, salt);
        return this.setDataValue('password', password);
      }
    },
    .....
Run Code Online (Sandbox Code Playgroud)

迁移文件:

"use strict";
module.exports = {
  up: function(migration, DataTypes, done) {
    migration.createTable("users", {
      id: {
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        type: DataTypes.INTEGER
      },
      userlevel: {
        type: DataTypes.STRING,
        defaultValue: '5'
      },
      restaurant: {
        type: DataTypes.STRING,
        defaultValue: ''
      },
      access: {
        type: DataTypes.STRING,
        defaultValue: '1'
      },
      optionsid: {
        type: DataTypes.STRING,
        defaultValue: ''
      },
      email: {
        type: DataTypes.STRING,
        allowNull: false
      },
      name: {
        type: DataTypes.STRING,
        defaultValue: ''
      },
      gender: {
        type: DataTypes.STRING,
        defaultValue: ''
      },
      location: {
        type: DataTypes.STRING,
        defaultValue: ''
      },
      website: {
        type: DataTypes.STRING,
        defaultValue: ''
      },
      picture: {
        type: DataTypes.STRING,
        defaultValue: ''
      },
      password: {
        type: DataTypes.STRING
      },
      facebook: {
        type: DataTypes.STRING
      },
      twitter: {
        type: DataTypes.STRING
      },
      google: {
        type: DataTypes.STRING
      },
      tokens: {
        type: DataTypes.STRING
      },
      resetPasswordToken: {
        type: DataTypes.STRING
      },
      resetPasswordExpires: {
        type: DataTypes.DATE
      },
      createdAt: {
        allowNull: false,
        type: DataTypes.DATE
      },
      updatedAt: {
        allowNull: false,
        type: DataTypes.DATE
      }
    }).done(done);
  },
  down: function(migration, DataTypes, done) {
    migration.dropTable("users").done(done);
  }
};
Run Code Online (Sandbox Code Playgroud)

如果我将postgreSQL中的第一个表格改为大写,那么一切正常......

Mik*_*ll' 12

PostgreSQL将普通标识符的名称折叠为小写.所以users,Users并且USERS所有解析标识符users.

定界标识符不同.(分隔标识符是由双引号所包围.)的标识符"users","Users"以及"USERS"三种不同的标识符.

您的迁移创建了表格"users".Sequelize正在寻找这张桌子"Users".(分隔标识符 - 两个不同的表.)

您应该将迁移中的标识符更改为"Users".还有其他方法,但这是阻力最小的路径.如果这是已经在生产,你可能会更好写另一迁移是重命名"users""Users".