Sails 1.0 Models without primary key

ⅰ亾dé卋堺 提交于 2019-12-24 07:41:48

问题


I try to use new version 1.0 and refactoring my project. I have one problem and i don't now how i can solve her. Some tables on my BD don't have primary keys and when i migrate to sails 1.0, i have this error

In model friends: The primary key is set to id, but no such attribute was found on the model. You must define an id attribute in api/Friends.js or in config/models.js. See http://sailsjs.com/upgrading#?changes-to-model-configuration for info

Can i use my model without primary keys?


回答1:


i have the same problem i used to change the primarykey this: in file config/model.js

attributes: {
      id: { 
         type: 'number', 
         autoIncrement: true, 
      },
    }

    and in the model api/any_model.js i used:

    tableName : 'table',
    attributes: {
      id: { 
       type: 'number',  
       columnName : 'column_you_like_to_be_a_primaryKEY',
       required : true
      },
    }



回答2:


I found a solution. I disable hook orm and now i'm happy =) Create file .sailsrc and write

{ "hooks": { "orm": false } }



来源:https://stackoverflow.com/questions/49736218/sails-1-0-models-without-primary-key

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