SQLite Android Base Date Problem

1

So, my problem is this, I tried and researched everything but I could not implement any solution. I tried to update the database with the update and also insert new columns with ALTER TABLE, nothing worked. I am a beginner so please be specific with the answers. Thank you.

Nome has no column named bairro (code 1): ,while compiling:
INSERT INTO Nome(email,bairro,rua,nomeDoCliente,telefoneResidencial,celular) VALUES (?,?,?,?,?,?)

//Create da classe Helper
db.execSQL("CREATE TABLE "
            + ClientesDAO.TABLE_NAME
            + " (" + ClientesDAO.ID
            + " INTEGER PRIMARY KEY,"
            + ClientesDAO.NOME_CLIENTE + " TEXT,"
            + ClientesDAO.RUA + " TEXT,"
            + ClientesDAO.EMAIL + " TEXT,"
            + ClientesDAO.BAIRRO + " TEXT,"
            + ClientesDAO.TELEFONE + " TEXT,"
            + ClientesDAO.CELULAR + " TEXT);"
);


//insert da classe ClientesDAO
public void insert(Clientes clientes){
    ContentValues cv = new ContentValues();
    cv.put(NOME_CLIENTE, clientes.getNome());
    cv.put(RUA, clientes.getRua());
    cv.put(BAIRRO, clientes.getBairro());
    cv.put(EMAIL, clientes.getEmail());
    cv.put(TELEFONE, clientes.getTelefone());
    cv.put(CELULAR, clientes.getCelular());

    db.getWritableDatabase().insert(TABLE_NAME, null, cv);
}


//Método setado no onClick da minha tela de cadastros
public void gravarNoBanco(){
    cd.insert(new Clientes(0, edit_nome.getText().toString(),edit_rua.getText().toString(),edit_email.getText().toString(),edit_bairro.getText().toString(),edit_telefone.getText().toString(),edit_celular.getText().toString()));
    clear();
}
    
asked by anonymous 26.07.2015 / 00:47

2 answers

1

As I understand it, the sachin garg response to a similar question in English can solve your problem too:

  

It seems like you have added some columns later in the database. You should consider uninstalling and reinstalling your application. A better approach is to drop and re-create all tables in the onUpdate method, and increment the database version every time you modify the schema.

    
26.07.2015 / 04:14
0

Raise the version of your database and implement the following method

@Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        //codigo para atualizar suas tabelas, alter table por exemplo
    }

Whenever the database version is increased, the onUpgrade method will be invoked the first time the database connection is instantiated after the version upgrade

    
28.07.2015 / 17:22