【问题标题】:How to properly migrate a sqlite3 database using the Sequelize.js ORM?如何使用 Sequelize.js ORM 正确迁移 sqlite3 数据库?
【发布时间】:2014-10-10 03:22:27
【问题描述】:

sequelize 似乎没有连接/打开我项目根目录中的 sqlite3 数据库文件。 sequelize -m 命令的输出表明一切都迁移得很好,但是 sqlite3 数据库文件仍然是空的。

config.json

{
  "development": {
    "username": null,
    "password": null,
    "database": "main",
    "host": "localhost",
    "dialect": "sqlite",
    "storage": "../data.sqlite3"
  }
}

20140814210910-createUsersTable.js(迁移文件)

'use strict';

module.exports = {
  up: function (migration, DataTypes, done) {
    migration.createTable('users', {
      id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true
      },
      createdAt: {
        type: DataTypes.DATE
      },
      updatedAt: {
        type: DataTypes.DATE
      },
      email: {
        type: DataTypes.STRING
      },
      password: {
        type: DataTypes.STRING
      }
    }).complete(done);
  },
  down: function (migration, DataTypes, done) {
    migration.dropTable('users').complete(done);
  }
};

终端输出

$ sequelize -m
Loaded configuration file "config/config.json".
Using environment "development".
Loaded configuration file "config/config.json".
Using environment "development".
Running migrations...
20140814210910-createUsersTable.js
Completed in 18ms

文件夹结构

|-.
   |-bin
   |-config
   |--config.json
   |-migrations
   |--20140814210910-createUsersTable.js
   |-node_modules
   |-server
   |-tests
   |-data.sqlite3

【问题讨论】:

标签: node.js sqlite sequelize.js


【解决方案1】:

错误是config.jsonstorage 的路径值。

编辑config.json阅读:

{
  "development": {
    "dialect": "sqlite",
    "storage": "data.sqlite3"
  }
}

它成功了。

【讨论】:

    猜你喜欢
    • 2021-10-25
    • 2013-06-12
    • 2014-02-02
    • 2021-05-05
    • 2019-01-09
    • 2012-02-17
    • 2016-02-28
    • 2016-07-04
    • 2014-04-18
    相关资源
    最近更新 更多