Я новичок в loopbackjs. Я пытаюсь выполнить мою первую автоматическую миграцию модели в базу данных MySQL. Стоит ли ожидать, что петля автоматически создаст базу данных, если она еще не существует? Или я всегда должен создавать базу данных вручную, используя инструменты mysql?
Вот некоторые из моих файлов:
datasource.json (в каталоге сервера)
{
"db": {
"name": "db",
"connector": "memory"
},
"dingobase": {
"host": "localhost",
"port": 3306,
"url": "",
"database": "dingo",
"password": "***",
"name": "dingobase",
"user": "root",
"connector": "mysql",
"insecureAuth": true,
"debug": true
}
}
archetype.json (в каталоге common / models)
{
"name": "Archetype",
"base": "PersistedModel",
"idInjection": false,
"options": {
"validateUpsert": true
},
"properties": {
"ArchetypeID": {
"type": "number",
"generated": true,
"id": true,
"required": true
},
"Name": {
"type": "string",
"required": true
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
model-config.json (в каталоге сервера)
{
"_meta": {
"sources": [
"loopback/common/models",
"loopback/server/models",
"../common/models",
"./models"
],
"mixins": [
"loopback/common/mixins",
"loopback/server/mixins",
"../common/mixins",
"./mixins"
]
},
"User": {
"dataSource": "db"
},
"AccessToken": {
"dataSource": "db",
"public": false
},
"ACL": {
"dataSource": "db",
"public": false
},
"RoleMapping": {
"dataSource": "db",
"public": false,
"options": {
"strictObjectIDCoercion": true
}
},
"Role": {
"dataSource": "db",
"public": false
},
"Archetype": {
"dataSource": "dingobase",
"public": true
}
}
automigrate.js (на сервере / при загрузке)
module.exports = function (app) {
app.dataSources.dingobase.automigrate();
console.log("Performed automigration.");
}
Когда я запускаю «узел». из командной строки я получаю ошибки:
Connection fails: Error: ER_BAD_DB_ERROR: Unknown database 'dingo'
It will be retried for the next request.
C:\Users\pchernoch\projects\LoopbackTest\Dingo\node_modules\mysql\lib\protocol\Parser.js:80
throw err; // Rethrow non-MySQL errors
^
Error: ER_BAD_DB_ERROR: Unknown database 'dingo'
at Handshake.Sequence._packetToError (C:\Users\pchernoch\projects\LoopbackTest\Dingo\node_modules\mysql\lib\protocol\sequences\Sequence.js:52:14)
at Handshake.ErrorPacket (C:\Users\pchernoch\projects\LoopbackTest\Dingo\node_modules\mysql\lib\protocol\sequences\Handshake.js:130:18)
at Protocol._parsePacket (C:\Users\pchernoch\projects\LoopbackTest\Dingo\node_modules\mysql\lib\protocol\Protocol.js:279:23)
at Parser.write (C:\Users\pchernoch\projects\LoopbackTest\Dingo\node_modules\mysql\lib\protocol\Parser.js:76:12)
at Protocol.write (C:\Users\pchernoch\projects\LoopbackTest\Dingo\node_modules\mysql\lib\protocol\Protocol.js:39:16) at Socket.<anonymous> (C:\Users\pchernoch\projects\LoopbackTest\Dingo\node_modules\mysql\lib\Connection.js:103:28)
at Socket.emit (events.js:180:13)
at addChunk (_stream_readable.js:274:12)
at readableAddChunk (_stream_readable.js:261:11)
at Socket.Readable.push (_stream_readable.js:218:10)
at TCP.onread (net.js:581:20)
--------------------
at Protocol._enqueue (C:\Users\pchernoch\projects\LoopbackTest\Dingo\node_modules\mysql\lib\protocol\Protocol.js:145:48)
at Protocol.handshake (C:\Users\pchernoch\projects\LoopbackTest\Dingo\node_modules\mysql\lib\protocol\Protocol.js:52:23)
at PoolConnection.connect (C:\Users\pchernoch\projects\LoopbackTest\Dingo\node_modules\mysql\lib\Connection.js:130:18)
at Pool.getConnection (C:\Users\pchernoch\projects\LoopbackTest\Dingo\node_modules\mysql\lib\Pool.js:48:16)
at MySQL.connect (C:\Users\pchernoch\projects\LoopbackTest\Dingo\node_modules\loopback-connector-mysql\lib\mysql.js:90:17)
at Object.initializeDataSource [as initialize] (C:\Users\pchernoch\projects\LoopbackTest\Dingo\node_modules\loopback-connector-mysql\lib\mysql.js:44:28)
at DataSource.setup (C:\Users\pchernoch\projects\LoopbackTest\Dingo\node_modules\loopback-datasource-juggler\lib\datasource.js:492:19)
at new DataSource (C:\Users\pchernoch\projects\LoopbackTest\Dingo\node_modules\loopback-datasource-juggler\lib\datasource.js:138:8)
at Registry.createDataSource (C:\Users\pchernoch\projects\LoopbackTest\Dingo\node_modules\loopback\lib\registry.js:362:12)
at dataSourcesFromConfig (C:\Users\pchernoch\projects\LoopbackTest\Dingo\node_modules\loopback\lib\application.js:560:19)
at Function.app.dataSource (C:\Users\pchernoch\projects\LoopbackTest\Dingo\node_modules\loopback\lib\application.js:267:14)
at C:\Users\pchernoch\projects\LoopbackTest\Dingo\node_modules\loopback-boot\lib\executor.js:191:9
at C:\Users\pchernoch\projects\LoopbackTest\Dingo\node_modules\loopback-boot\lib\executor.js:282:5
at Array.forEach (<anonymous>)
at forEachKeyedObject (C:\Users\pchernoch\projects\LoopbackTest\Dingo\node_modules\loopback-boot\lib\executor.js:281:20)
at setupDataSources (C:\Users\pchernoch\projects\LoopbackTest\Dingo\node_modules\loopback-boot\lib\executor.js:181:3)
Emitted 'error' event at:
at DataSource.postInit (C:\Users\pchernoch\projects\LoopbackTest\Dingo\node_modules\loopback-datasource-juggler\lib\datasource.js:479:16)
at C:\Users\pchernoch\projects\LoopbackTest\Dingo\node_modules\loopback-connector-mysql\lib\mysql.js:102:19
at Handshake.onConnect [as _callback] (C:\Users\pchernoch\projects\LoopbackTest\Dingo\node_modules\mysql\lib\Pool.js:58:9)
at Handshake.Sequence.end (C:\Users\pchernoch\projects\LoopbackTest\Dingo\node_modules\mysql\lib\protocol\sequences\Sequence.js:88:24)
at Handshake.ErrorPacket (C:\Users\pchernoch\projects\LoopbackTest\Dingo\node_modules\mysql\lib\protocol\sequences\Handshake.js:132:8)
at Protocol._parsePacket (C:\Users\pchernoch\projects\LoopbackTest\Dingo\node_modules\mysql\lib\protocol\Protocol.js:279:23)
[... lines matching original stack trace ...]
at TCP.onread (net.js:581:20)