Sails js - waterline orm - mysql. Tables autogeneration

夙愿已清 提交于 2019-12-11 12:33:13

问题


When I create my model in sails - waterline the db is autogenerated. The problem is that my primary keys are unsigned int(10) and the external keys are int(11) (with sign). In fact the relationship is only in my models and not in db. A code example is the following:

// A user may only have a single pet
var User = Waterline.Collection.extend({

identity: 'user',
connection: 'local-postgresql',

attributes: {
  firstName: 'string',
  lastName: 'string',

// Add a reference to Pet
  pet: {
    model: 'pet'
  }
 }
});

var Pet = Waterline.Collection.extend({

 identity: 'pet',
 connection: 'local-postgresql',

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

   // Add a reference to User
   user: {
     model: 'user'
   }
 }
});

In this example my database is generated in the following way: pet "id" (in pet table) is an autoincrement primary key unsigned int(10) and "pet" (in user table that is an external key pointing to pet id) is a int(11) (signed int). There is a solution to that problem? thanks


回答1:


The sails-postgresql adapter does not yet create foreign key relationships in the database itself. This is not incorrect and doesn't affect how you use sails/waterline. Everything will work fine, this is just an optimization that hasn't been implemented yet.

There's an open issue if you'd like to share your thoughts there: https://github.com/balderdashy/sails-postgresql/issues/123



来源:https://stackoverflow.com/questions/29427734/sails-js-waterline-orm-mysql-tables-autogeneration

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