is there a way, to change the primary key of ORMlite defined databases ?
i’m having a class User with
@DatabaseField(columnName = NAME_FIELD_NAME, canBeNull = false, id = true)
private String name = "";
and i query it with DAO.querybyid(String name);
But when i try to alter the name in the database, it doesn’t give me any warnings, will ORMLite alter the table column and remove the index, and then update the column and place the index again ?
I don’t think so heh ? so need a workaround 🙁 but also want the DAO.querybyid() advantage to get the user by String.
Can someone help me ?
I assume you are altering your schema using the
dao.rawExecute(...)method? ORMLite doesn’t do anything magical with this statement — it just sends it to the underlying database. So if you are asking for the fieldnamebut it’s been renamed to beidthen the DAO will not work since it doesn’t correspond to the database. It will do a"SELECT name, ... FROM ..."and get a SQL error.What you can do is have two different versions of the class. The first one has it with the “old” field-name and the new one has it with the “new” name. Then if you detect that you need to update the schema, you can issue the raw
ALTERSQL statements, and then start using the DAO corresponding to the new version of the class.