Loopback-next: migrateSchema will not work if there is blongTo relationship

Created on 27 Jun 2019  路  2Comments  路  Source: strongloop/loopback-next

Steps to reproduce

I'm new to LoopBack4, and I was following the tutorials to generate a simple blog API using LoopBack, and I knew I can use 'migrateSchema' to create database tables using my models.


Just follow the tutorial to generate the simple order, customer model and relationships, and try to run the app after adding the relationship (this link)

Current Behavior

When I use npm strat I get this error:

Cannot start the application. TypeError: Cannot read property 'target' of undefined
    at resolveBelongsToMetadata (E:\personal\project\node_modules\@loopback\repository\dist\relations\belongs-to\belongs-to-accessor.js:37:54)
    at Object.createBelongsToAccessor (E:\personal\project\node_modules\@loopback\repository\dist\relations\belongs-to\belongs-to-accessor.js:16:18)
    at StoryRepository.createBelongsToAccessorFor (E:\personal\project\node_modules\@loopback\repository\dist\repositories\legacy-juggler-bridge.js:184:28)
    at new StoryRepository (E:\personal\project\node_modules\dist\repositories\story.repository.js:22:26)

Link to reproduction sanbox

https://github.com/m98/loopback4-example/tree/master/src

Additional information

Windows 10 'win32', 'x64', '10.16.0'

bug

Most helpful comment

Actually, I'm disappointed by loopback documentation, and also errors which are not meaningful, especially when you search them on Google, and you can't find anything meaningful by the loopback error message.

All 2 comments

In order to do that, we'll need strong relation with referential integrity which is captured in https://github.com/strongloop/loopback-next/issues/2331.

As a workaround, this documentation page (https://loopback.io/doc/en/lb4/todo-list-tutorial-sqldb.html) showed how to modify the @model decorator to contain the foreign key information when running migrateSchema.

Hope it helps.

Actually, I'm disappointed by loopback documentation, and also errors which are not meaningful, especially when you search them on Google, and you can't find anything meaningful by the loopback error message.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rexliu0715 picture rexliu0715  路  3Comments

mightytyphoon picture mightytyphoon  路  3Comments

shahulhameedp picture shahulhameedp  路  3Comments

acrodrig picture acrodrig  路  3Comments

kesavkolla picture kesavkolla  路  3Comments