如何在 ormlite ( SQLite ) 中进行多列唯一约束 [英] How to do multiple column unique-constraint in ormlite ( SQLite )

查看:85
本文介绍了如何在 ormlite ( SQLite ) 中进行多列唯一约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 Android 使用 ormlite,并且我正在尝试获得多列唯一约束.截至目前,我只能对这样的单个列获得唯一约束:

I'm using ormlite for Android and I'm trying to get a multiple column unique-constraint. As of now i'm only able to get a unique constraint on indiviudal columns like this:

CREATE TABLE `store_group_item` (`store_group_id` INTEGER NOT NULL UNIQUE ,
    `store_item_id` INTEGER NOT NULL UNIQUE ,
    `_id` INTEGER PRIMARY KEY AUTOINCREMENT );

我想要的是

CREATE TABLE `store_group_item` (`store_group_id` INTEGER NOT NULL ,
    `store_item_id` INTEGER NOT NULL ,
    `_id` INTEGER PRIMARY KEY AUTOINCREMENT,
    UNIQUE( `store_group_id`, `store_item_id` );

在我的模型中,我一直在为唯一列使用以下注释:

In my model I've been using the following annotations for the unique columns:

@DatabaseField( unique = true )

有没有办法让它起作用?

Is there a way to get this to work?

推荐答案

如何使用

@DatabaseField (uniqueCombo = true) 
String myField;

改为注释 - 访问表中的项目时 uniqueIndexName 是否更快?

annotation instead - is it a matter of the uniqueIndexName being faster when accessing items in the table?

这篇关于如何在 ormlite ( SQLite ) 中进行多列唯一约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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