问题描述
我想创建一个表,第一次(DB版本= 1),默认情况下插入其2行。该表需要由ActiveAndroid自动创建和记录应该由SQL我1.SQL文件中写道插入。
表看起来不错,但行是不是在所有插入的(抛出任何错误)。
这个模型是这样的:
@Table(name =联盟)
公共类联赛的扩展模式实现Serializable {
@Column(名称=名称)
公共字符串名称;
公共静态列表<联赛> GETALL(){
返回新选择()
。从(League.class)
.orderBy(名ASC)
。执行();
}
}
和1.SQL:
INSERT INTO联赛(ID,姓名)VALUES(1,'premier联盟');
显然这ActiveAndroid认为数据库的版本为0,在应用程序的初始设置。因此,该文件1.SQL具有比DB号更大的版本,它会被跳过!
要使其工作,脚本的名称应该是0.sql。
I want to create a table for the first time (DB version = 1), and insert into it 2 rows by default.The table needs to be created automatically by ActiveAndroid, and the records should be inserted by the SQL I wrote in 1.sql file.
The table looks fine, but the rows are not inserted at all (no errors thrown).
The model looks like this:
@Table(name = "leagues")
public class League extends Model implements Serializable{
@Column(name = "name")
public String name;
public static List<League> getAll() {
return new Select()
.from(League.class)
.orderBy("name ASC")
.execute();
}
}
and the 1.sql:
INSERT INTO leagues (Id, name) VALUES (1, 'Premier league');
Apparently that ActiveAndroid thinks the version of the DB is 0 in the initial setup of the app.So, the file "1.sql" has a bigger version than the DB number and it will be skipped!
To make it work, the script name should be "0.sql".
这篇关于使用模式迁移ActiveAndroid pre填入表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!