-1

I made a DbFlow migration for my SQLite Db. I added two columns and the build was successful The problem is I cant see those columns anywhere in the User table and i cant insert or read data from them. What could be the problem ?

My migration code.

package com.omnitech.elunda.mobile.database;

import com.raizlabs.android.dbflow.annotation.Database;
import com.raizlabs.android.dbflow.annotation.Migration;
import com.raizlabs.android.dbflow.sql.SQLiteType;
import com.raizlabs.android.dbflow.sql.migration.AlterTableMigration;

/**
 * Created by magicwand on 9/28/2017.
 * Database class to manage datastore
 */

@Database(name=ELundaDatabase.name , version=ELundaDatabase.VERSION)
public class ELundaDatabase {

    public static final String name ="ElundaDatabase";
    public static final int VERSION =1;

    @Migration(version = ELundaDatabase.VERSION +1, database=ELundaDatabase.class)
    public static class Migration1 extends AlterTableMigration<User> {


        public Migration1(Class<User> table) {
            super(table);
        }

        @Override
        public void onPreMigrate() {
            super.onPreMigrate();
            addColumn(SQLiteType.TEXT, "phoneNumber");
            addColumn(SQLiteType.TEXT, "password");
        }
    }



}
henrybbosa
  • 1,139
  • 13
  • 28

1 Answers1

1

Upgrade the DB version to same as altertable version. Use same name in model also else use column name annotation

public static final String name ="ElundaDatabase";
public static final int VERSION = 2;


@Migration(version = 2, database=ELundaDatabase.class)
public static class Migration1 extends AlterTableMigration<User> {


    public Migration1(Class<User> table) {
        super(table);
    }

    @Override
    public void onPreMigrate() {
        super.onPreMigrate();
        addColumn(SQLiteType.TEXT, "phoneNumber");
        addColumn(SQLiteType.TEXT, "password");
    }
}

/// Model e.g

@Column(name = "time_sent")
long timeSent;
Jarvis
  • 1,714
  • 2
  • 20
  • 35