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