没有主键的 Sails 1.0 模型 [英] Sails 1.0 Models without primary key

查看:33
本文介绍了没有主键的 Sails 1.0 模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用新版本 1.0 并重构我的项目.我有一个问题,我现在不知道如何解决她.我的 BD 上的某些表没有主键,当我迁移到sails 1.0 时,出现此错误

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

在模型friends中:主键设置为id,但没有这样的在模型上找到了属性.您必须在中定义 id 属性api/Friends.js 或在 config/models.js 中.看http://sailsjs.com/upgrading#?changes-to-model-configuration 对于信息

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?

推荐答案

我有同样的问题,我用来改变主键:在文件 config/model.js

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
      },
    }

这篇关于没有主键的 Sails 1.0 模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆