【问题标题】:Sails 1.0 Models without primary keySails 1.0 没有主键的模型
【发布时间】:2018-09-19 01:05:20
【问题描述】:

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

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

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

【问题讨论】:

    标签: sails.js waterline


    【解决方案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
          },
        }
    

    【讨论】:

      猜你喜欢
      • 2022-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多