【发布时间】:2015-06-08 06:44:11
【问题描述】:
当我在sails - waterline 中创建我的模型时,数据库是自动生成的。 问题是我的主键是 unsigned int(10) 而外部键是 int(11) (带符号)。事实上,这种关系只存在于我的模型中,而不存在于 db 中。 代码示例如下:
// 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'
}
}
});
在这个例子中,我的数据库是通过以下方式生成的: 宠物“id”(在宠物表中)是一个自动增量主键 unsigned int(10) 并且“pet”(在用户表中是指向宠物 id 的外部键)是 int(11)(有符号整数)。有解决这个问题的办法吗?谢谢
【问题讨论】:
-
要停止自动生成吗?
-
不,我想要一个正确的世代!有可能吗?如果我保留主键 unsigned int 和外键 signed int 会发生什么?会不会有意想不到的结果?
标签: mysql orm sails.js waterline