loopback-example-database icon indicating copy to clipboard operation
loopback-example-database copied to clipboard

create-test-data.js doesn't work with mysql database

Open xinshouke opened this issue 12 years ago • 5 comments

I am sure my dataSource may connect db successfully, and I log the informations to debug the code, and I log the result output at last: -----------------create-test-data.js content------------------------- var app = require('./server'); console.log('createdata.......1'); var dataSource = app.dataSources.cduserds; console.log('createdata.......2'); var Account = app.models.account; console.log('createdata.......3'); var accounts = [ { email: "[email protected]", level: 10, created: new Date(), modified: new Date() }, { email: "[email protected]", level: 20, created: new Date(), modified: new Date() } ]; console.log('createdata.......4'); var count = accounts.length; console.log('count========>'+count); dataSource.automigrate('account', function (err) { console.log('createdata.......5'); accounts.forEach(function(act) { Account.create(act, function(err, result) { if(!err) { console.log('Record created:', result); count--; if(count === 0) { console.log('done'); dataSource.disconnect(); } } }); console.log('createdata.......6'); }); });

--------------------------------console output--------------------------------------- createdata.......1 createdata.......2 createdata.......3 createdata.......4 count========>2

xinshouke avatar Sep 11 '14 12:09 xinshouke

Please try to run with ‘DEBUG=loopback:connector:mysql node create-test-data’ to see what’s going on.

Thanks,


Raymond Feng Co-Founder and Architect @ StrongLoop, Inc.

StrongLoop makes it easy to develop APIs in Node, plus get DevOps capabilities like monitoring, debugging and clustering.

On Sep 11, 2014, at 5:47 AM, Yi Leung [email protected] wrote:

I am sure my dataSource may connect db successfully, and I log the informations to debug the code, and I log the result output at last: -----------------create-test-data.js content------------------------- var app = require('./server'); console.log('createdata.......1'); var dataSource = app.dataSources.cduserds; console.log('createdata.......2'); var Account = app.models.account; console.log('createdata.......3'); var accounts = [ { email: "[email protected]", level: 10, created: new Date(), modified: new Date() }, { email: "[email protected]", level: 20, created: new Date(), modified: new Date() } ]; console.log('createdata.......4'); var count = accounts.length; console.log('count========>'+count); dataSource.automigrate('account', function (err) { console.log('createdata.......5'); accounts.forEach(function(act) { Account.create(act, function(err, result) { if(!err) { console.log('Record created:', result); count--; if(count === 0) { console.log('done'); dataSource.disconnect(); } } }); console.log('createdata.......6'); }); });

--------------------------------console output--------------------------------------- createdata.......1 createdata.......2 createdata.......3 createdata.......4 count========>2

— Reply to this email directly or view it on GitHub.

raymondfeng avatar Sep 11 '14 15:09 raymondfeng

@xinshouke Are you following the new 2.x examples? I see some of the older code from the 1.x examples like {...level:20...} which was removed.

superkhau avatar Sep 11 '14 21:09 superkhau

@superkhau yes, I started loopup from version 2.0

xinshouke avatar Sep 12 '14 03:09 xinshouke

have you tried copying and pasting create-test-data.js? Do you get output after running node create-test-data?

superkhau avatar Sep 12 '14 03:09 superkhau

@superkhau Thanks, it works with the value for level, because the property is required according to doc 'Getting started with LoopBack'. I will upload my file executed well

xinshouke avatar Sep 12 '14 07:09 xinshouke