jeudi 13 août 2015

How do I add 2 columns to my Android SQLlite database?

I have a 2.sql file under assets/migrations with this

ALTER TABLE Business ADD COLUMN name STRING; ALTER TABLE Business ADD COLUMN time_zone STRING;

I want to add 2 columns, one String and 1 Integer.

So I made 3.sql in the same directory:

ALTER TABLE Business ADD COLUMN background_image_uri STRING; ALTER TABLE Business ADD COLUMN background_image_number INTEGER DEFAULT 0;

and added this to Business.java under my Class definition:

@Column(name = "background_image_uri")
public String backgroundImageURI;

@Column(name = "background_image_number")
public int backgroundImageNumber;

I can set the variables fine, but it crashes when I try to save & load from disk.

How do I run this migration?

Aucun commentaire:

Enregistrer un commentaire