无法在mysql环回3中自动创建模型表

问题描述 投票:0回答:1

我是Loopback框架的新手。我经历了入门和模型创建过程,并尝试创建测试应用程序。我通过命令-> lb创建了应用程序并通过-> lb datasource创建mysql数据源并通过-> lb model创建了两个模型正在使用mysql数据源。

{
  "name": "Brand",
  "plural": "brands",
  "base": "PersistedModel",
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "name": {
      "type": "string",
      "required": true
    }
  },
  "validations": [],
  "relations": {},
  "acls": [],
  "methods": {}
}

所以现在当我通过npm start启动应用程序并转到localhost:3000/explorer并尝试使用任何端点时,出现以下表格未找到错误。Unhandled error for request GET /api/brands: Error: ER_NO_SUCH_TABLE: Table 'loop3.Brand' doesn't exist

环回会自动在数据库中创建表吗?否则我将不得不为每个模型创建autoMigrate文件,或者应该如何做,请帮助。

我是Loopback框架的新手。我经历了入门和模型创建过程,并尝试创建测试应用程序。我通过命令-> lb创建了应用程序,并通过-> ...

node.js loopbackjs
1个回答
0
投票

您需要运行automigrate函数以在数据库中创建表架构。您可以将其添加到启动脚本中,该脚本将在每次启动应用程序时运行。参见以下示例:https://github.com/ssh24/loopback-sandbox/blob/master/apps/mysql/mysql-101/server/boot/script.js

© www.soinside.com 2019 - 2024. All rights reserved.