MySQL table 安装 MySQL 连接器后,自动创建在环回节点 API 框架中不起作用

MySQL table auto creation is not working in Loopback node API framework after installing MySQL connectors

1.I 使用 "lb demo" 命令在环回中创建了一个演示应用程序。

2.Then,使用 "npm install loopback-connector-mysql --save" 此命令成功安装了 MySQL 个连接器。

3.Then 使用 firstName 和 lastName 属性创建用户模型。

  1. 尝试在“http://localhost:3000/explorer/”上使用 GUI 资源管理器 post 数据,但抛出 "TABLE NOT EXIST ERROR"。

或者我们是否需要手动创建 MySQL 表。?

请提出任何解决方案。我为此尝试了很多但无法解决问题。

提前致谢。

根据您的步骤,您从未尝试过自动创建它们。

要调用自动迁移,请尝试使用以下代码创建 server/bin/automigrate.js,然后在项目目录

中 运行 node server/bin/automigrate
var server = require('./server');
var ds = server.dataSources.MYDATASOURCE;
var lbTables = ['myUserModel', 'anotherModelIWantToCreate'];
ds.automigrate(lbTables, function(er) {
  if (er) throw er;
  console.log('Loopback tables [' - lbTables - '] created in ', ds.adapter.name);
  ds.disconnect();
});

https://loopback.io/doc/en/lb3/Creating-a-database-schema-from-models.html

Warning: Auto-migration will drop an existing table if its name matches a model name. When tables with data exist, use auto-update to avoid data loss.