Unique 不适用于 Node.js Sails.js “sails-mysql"; [英] Unique doesn't work on Node.js Sails.js "sails-mysql"
问题描述
我刚刚开始接触用于 Node.js 的 Sails 框架.但是,在将例如用户添加到sails-mysql 数据库时,我似乎无法满足工作的独特要求.我可以使用相同的用户名和电子邮件地址添加无限数量的新用户.
I've just started to get into the framework of Sails for Node. But it seems like I can't get the unique- requirements to work when adding for example users to the sails-mysql database. I can atm add unlimited number of new users with the same username and email.
从我读到的内容来看,它应该可以工作,我也尝试过使用帆内存,并且这个确切的代码确实有效.是我遗漏了什么吗?
From what I have read it should work, I did also try with sails-memory and there this exact code did work. Is it something I have missed out?
module.exports = {
attributes: {
username: {
type: 'string',
required: true,
unique: true
},
firstname: {
type: 'string',
required: true
},
lastname: {
type: 'string',
required: true
},
password: {
type: 'string',
required: true
},
birthdate: {
type: 'date',
required: true
},
email: {
type: 'email',
required: true,
unique: true
},
phonenumber: 'string',
// Create users full name automaticly
fullname: function(){
return this.firstname + ' ' + this.lastname;
}
}
};
正如我上面提到的,这确实适用于内存存储.现在我也尝试过使用 mongodb,它也可以使用 fins.
As I mentioned above, this does work with the memory-storage. And now I have also tried with mongodb where it does work fins as well.
推荐答案
在 twitter 上得到了 Sails.js 的支持:它使用了 db 层 - 怀疑这是自动迁移的问题.你会尝试使用新的 MySQL 数据库吗?"
Got support from Sails.js on twitter: "it uses the db layer- suspect it's an issue with automigrations. Would you try in a new MySQL db?"
这个答案确实有效,一个新的数据库,一切正常:)
This answer did work, a new db and everything was just working :)
这篇关于Unique 不适用于 Node.js Sails.js “sails-mysql";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!