create-test-data.js doesn't work with mysql database
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
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.
@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 yes, I started loopup from version 2.0
have you tried copying and pasting create-test-data.js? Do you get output after running node create-test-data?
@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