sails v10.0 on mysql encountering 'schema' of undefined

↘锁芯ラ 提交于 2019-12-25 07:04:30

问题


i'm trying out sails js version 0.10.0 with sails-mysql adapter 0.10.6

I created two models:

Customer.js

module.exports = {

  connection: 'someMysqlServer',

  attributes: {
    name: {
        type: 'string'
    },

    store: {
        model: 'Store'
    }
  }
};

and Store.js

module.exports = {

  connection: 'someMysqlServer',

  attributes: {
    name: {
        type: 'string'
    },

    customers: {
        model: 'Customer',
        required: false
    }
  }
};

when I first run the application, all is fine and I can see that it created two tables on my database. However, when I try to restart the application I am getting this error:

TypeError: Cannot read property 'schema' of undefined
    at __FIND__ (C:\fray\NodeJs\testingsails10_2\test1001\node_modules\sails-mys
ql\lib\adapter.js:808:42)
    at afterwards (C:\fray\NodeJs\testingsails10_2\test1001\node_modules\sails-m
ysql\lib\connections\spawn.js:86:5)
    at C:\fray\NodeJs\testingsails10_2\test1001\node_modules\sails-mysql\lib\con
nections\spawn.js:40:7
    at Ping._callback (C:\fray\NodeJs\testingsails10_2\test1001\node_modules\sai
ls-mysql\node_modules\mysql\lib\Pool.js:81:7)
    at Ping.Sequence.end (C:\fray\NodeJs\testingsails10_2\test1001\node_modules\
sails-mysql\node_modules\mysql\lib\protocol\sequences\Sequence.js:78:24)
    at Ping.Sequence.OkPacket (C:\fray\NodeJs\testingsails10_2\test1001\node_mod
ules\sails-mysql\node_modules\mysql\lib\protocol\sequences\Sequence.js:87:8)
    at Protocol._parsePacket (C:\fray\NodeJs\testingsails10_2\test1001\node_modu
les\sails-mysql\node_modules\mysql\lib\protocol\Protocol.js:213:24)
    at Parser.write (C:\fray\NodeJs\testingsails10_2\test1001\node_modules\sails
-mysql\node_modules\mysql\lib\protocol\Parser.js:62:12)
    at Protocol.write (C:\fray\NodeJs\testingsails10_2\test1001\node_modules\sai
ls-mysql\node_modules\mysql\lib\protocol\Protocol.js:37:16)
    at Socket.<anonymous> (C:\fray\NodeJs\testingsails10_2\test1001\node_modules
\sails-mysql\node_modules\mysql\lib\Connection.js:75:28)

and if I drop the tables and restart the application, it'll be able to run and re-create the table, but won't go further, when I get to this controller.

module.exports = {
    add: function(req, res){
        var store = {
            name: 'strore2'
        }
        Store.create(store).exec(function(err, result){
            Customer.create({name: 'customer1', store: result.id}).exec(function (err1, result1){
                return res.json({created: result1, error: err1});   
            });
        });

    }

};

and will throw this error:

TypeError: Cannot read property 'schema' of undefined
    at __CREATE__ (C:\fray\NodeJs\testingsails10_2\test1001\node_modules\sails-m
ysql\lib\adapter.js:386:42)
    at afterwards (C:\fray\NodeJs\testingsails10_2\test1001\node_modules\sails-m
ysql\lib\connections\spawn.js:86:5)
    at C:\fray\NodeJs\testingsails10_2\test1001\node_modules\sails-mysql\lib\con
nections\spawn.js:40:7
    at Ping._callback (C:\fray\NodeJs\testingsails10_2\test1001\node_modules\sai
ls-mysql\node_modules\mysql\lib\Pool.js:81:7)
    at Ping.Sequence.end (C:\fray\NodeJs\testingsails10_2\test1001\node_modules\
sails-mysql\node_modules\mysql\lib\protocol\sequences\Sequence.js:78:24)
    at Ping.Sequence.OkPacket (C:\fray\NodeJs\testingsails10_2\test1001\node_mod
ules\sails-mysql\node_modules\mysql\lib\protocol\sequences\Sequence.js:87:8)
    at Protocol._parsePacket (C:\fray\NodeJs\testingsails10_2\test1001\node_modu
les\sails-mysql\node_modules\mysql\lib\protocol\Protocol.js:213:24)
    at Parser.write (C:\fray\NodeJs\testingsails10_2\test1001\node_modules\sails
-mysql\node_modules\mysql\lib\protocol\Parser.js:62:12)
    at Protocol.write (C:\fray\NodeJs\testingsails10_2\test1001\node_modules\sai
ls-mysql\node_modules\mysql\lib\protocol\Protocol.js:37:16)
    at Socket.<anonymous> (C:\fray\NodeJs\testingsails10_2\test1001\node_modules
\sails-mysql\node_modules\mysql\lib\Connection.js:75:28)

回答1:


This seems like a broken dependencies issue. Try:

rm -rf node_modules
npm cache clear
npm install

To reinstall all the dependencies, then try sails lift.

At this point you will have Sails installed locally in your project, and sails lift will use that copy. To perform a similar surgery on your global sails install, do:

sudo npm uninstall -g sails
npm cache clear
sudo npm install -g sails

Then rm -rf node_modules/sails in your project so that sails lift will use the global install.



来源:https://stackoverflow.com/questions/25558153/sails-v10-0-on-mysql-encountering-schema-of-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!