Sails 1.0 Models without primary key

时间:2018-04-09 15:09:56

标签: sails.js waterline

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   信息

我可以在没有主键的情况下使用我的模型吗?

2 个答案:

答案 0 :(得分:1)

我遇到了我用来更改主键的相同问题: 在文件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
      },
    }

答案 1 :(得分:0)

我找到了解决方案。 我禁用钩子orm,现在我很高兴=) 创建文件.sailsrc并写入

  

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