{"action":"created","issue":{"url":"https://api.github.com/repos/realm/realm-java/issues/1826","labels_url":"https://api.github.com/repos/realm/realm-java/issues/1826/labels{/name}","comments_url":"https://api.github.com/repos/realm/realm-java/issues/1826/comments","events_url":"https://api.github.com/repos/realm/realm-java/issues/1826/events","html_url":"https://github.com/realm/realm-java/issues/1826","id":118814765,"number":1826,"title":"io.realm.exceptions.RealmMigrationNeededException: Field 'issueDate' not found for Type InsuranceCard","user":{"login":"iamMehedi","id":3691635,"avatar_url":"https://avatars.githubusercontent.com/u/3691635?v=3","gravatar_id":"","url":"https://api.github.com/users/iamMehedi","html_url":"https://github.com/iamMehedi","followers_url":"https://api.github.com/users/iamMehedi/followers","following_url":"https://api.github.com/users/iamMehedi/following{/other_user}","gists_url":"https://api.github.com/users/iamMehedi/gists{/gist_id}","starred_url":"https://api.github.com/users/iamMehedi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iamMehedi/subscriptions","organizations_url":"https://api.github.com/users/iamMehedi/orgs","repos_url":"https://api.github.com/users/iamMehedi/repos","events_url":"https://api.github.com/users/iamMehedi/events{/privacy}","received_events_url":"https://api.github.com/users/iamMehedi/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/realm/realm-java/labels/Help","name":"Help","color":"cc317c"},{"url":"https://api.github.com/repos/realm/realm-java/labels/Pending","name":"Pending","color":"ededed"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-11-25T11:16:51Z","updated_at":"2015-11-25T14:01:09Z","closed_at":null,"body":"in earlier version of the app:\r\nRealm version: 0.82.2\r\nGradle version: 1.1.0\r\nSchema version: 2\r\n\r\n`InsuranceCard.java` looks like this (`issueDate` is defined)\r\n\r\n```java    \r\npublic class InsuranceCard extends RealmObject{\r\n    public final static String CREDENTIAL_ID_FIELD_NAME = \"credentialId\";\r\n\r\n    @PrimaryKey\r\n    private String credentialId;\r\n    private RealmList<CredentialImage> credentialImages;\r\n\r\n    private int backImageOrientation = LocalDBHelper.DEFAULT_INT_VALUE;\r\n    private String barcodeType = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private String barcodeData = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private long createdAt = LocalDBHelper.DEFAULT_LONG_VALUE;\r\n    private int displayOrder = LocalDBHelper.DEFAULT_INT_VALUE;\r\n    private long expireDate = LocalDBHelper.DEFAULT_LONG_VALUE;\r\n    private String firstName = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private int frontImageOrientation = LocalDBHelper.DEFAULT_INT_VALUE;\r\n    private long issueDate = LocalDBHelper.DEFAULT_LONG_VALUE;\r\n    private String issuer = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private String lastName = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private String middleName = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private String number = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private String objectId = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private String credentialName = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private boolean shared = false;\r\n    private boolean vertical = false;\r\n    private boolean verified = false;\r\n    private String suffix = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n\r\n    private String groupName = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private String groupNo = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private String planType = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private String planAdmin = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n\r\n    //optional values\r\n    private String webAddress = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private String emailAddress = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private String PhoneNoPrimary = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private String PhoneNoSecondary = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private String address = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private String city = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private String state = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private String zipCode = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n\r\n    public static List<DBColumn> getColumns(){\r\n        List<DBColumn> columns = new ArrayList<>();\r\n\r\n        DBColumn primaryColumn = new DBColumn(ColumnType.STRING, CREDENTIAL_ID_FIELD_NAME);\r\n        primaryColumn.setIsPrimaryKey(true);\r\n\r\n        columns.add(primaryColumn);\r\n        columns.add(new DBColumn(ColumnType.LINK_LIST, \"credentialImages\", CredentialImage.class));\r\n        columns.add(new DBColumn(ColumnType.INTEGER, \"backImageOrientation\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"barcodeType\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"barcodeData\"));\r\n        columns.add(new DBColumn(ColumnType.INTEGER, \"createdAt\"));\r\n        columns.add(new DBColumn(ColumnType.INTEGER, \"displayOrder\"));\r\n        columns.add(new DBColumn(ColumnType.INTEGER, \"expireDate\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"firstName\"));\r\n        columns.add(new DBColumn(ColumnType.INTEGER, \"frontImageOrientation\"));\r\n        columns.add(new DBColumn(ColumnType.INTEGER, \"issueDate\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"issuer\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"lastName\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"middleName\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"number\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"objectId\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"credentialName\"));\r\n        columns.add(new DBColumn(ColumnType.BOOLEAN, \"shared\"));\r\n        columns.add(new DBColumn(ColumnType.BOOLEAN, \"vertical\"));\r\n        columns.add(new DBColumn(ColumnType.BOOLEAN, \"verified\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"suffix\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"groupName\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"groupNo\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"planType\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"planAdmin\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"webAddress\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"emailAddress\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"PhoneNoPrimary\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"PhoneNoSecondary\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"address\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"city\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"state\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"zipCode\"));\r\n\r\n        return Collections.unmodifiableList(columns);\r\n    }\r\n    //--------getters setters constructors etc.\r\n    }\r\n```\r\nin a later version of the app:\r\nRealm version: 0.82.2\r\nGradle version: 1.1.0\r\nSchema version: 3\r\n\r\n`InsuranceCard.java` looks like this (`issueDate` is still there and not modified):\r\n\r\n```java\r\npublic class InsuranceCard extends RealmObject{\r\n    public final static String CREDENTIAL_ID_FIELD_NAME = \"credentialId\";\r\n\r\n    @PrimaryKey\r\n    private String credentialId;\r\n    private RealmList<CredentialImage> credentialImages;\r\n\r\n    private String barcodeType = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private String barcodeData = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private long createdAt = LocalDBHelper.DEFAULT_LONG_VALUE;\r\n    private int displayOrder = LocalDBHelper.DEFAULT_INT_VALUE;\r\n    private long expireDate = LocalDBHelper.DEFAULT_LONG_VALUE;\r\n    private String firstName = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n\r\n    private long issueDate = LocalDBHelper.DEFAULT_LONG_VALUE;\r\n\r\n    private String issuer = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private String lastName = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private String middleName = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private String number = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private String objectId = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private String credentialName = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private boolean shared = false;\r\n    private boolean vertical = false;\r\n    private boolean verified = false;\r\n    private String suffix = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n\r\n    private String groupName = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private String groupNo = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private String planType = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private String planAdmin = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n\r\n    //optional values\r\n    private String webAddress = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private String emailAddress = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private String PhoneNoPrimary = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private String PhoneNoSecondary = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private String address = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private String city = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private String state = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n    private String zipCode = LocalDBHelper.DEFAULT_STRING_VALUE;\r\n\r\n    private boolean synced = false, deleted = false;\r\n\r\n    /**\r\n     * Used for database migration only. from version 1 to 2\r\n     * @return - A list of columns that this table has, along with their data types\r\n     */\r\n    public static List<DBColumn> getColumns(){\r\n        List<DBColumn> columns = new ArrayList<>();\r\n\r\n        DBColumn primaryColumn = new DBColumn(ColumnType.STRING, CREDENTIAL_ID_FIELD_NAME);\r\n        primaryColumn.setIsPrimaryKey(true);\r\n\r\n        columns.add(primaryColumn);\r\n        columns.add(new DBColumn(ColumnType.LINK_LIST, \"credentialImages\", CredentialImage.class));\r\n        columns.add(new DBColumn(ColumnType.INTEGER, \"backImageOrientation\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"barcodeType\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"barcodeData\"));\r\n        columns.add(new DBColumn(ColumnType.INTEGER, \"createdAt\"));\r\n        columns.add(new DBColumn(ColumnType.INTEGER, \"displayOrder\"));\r\n        columns.add(new DBColumn(ColumnType.INTEGER, \"expireDate\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"firstName\"));\r\n        columns.add(new DBColumn(ColumnType.INTEGER, \"frontImageOrientation\"));\r\n        columns.add(new DBColumn(ColumnType.INTEGER, \"issueDate\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"issuer\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"lastName\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"middleName\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"number\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"objectId\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"credentialName\"));\r\n        columns.add(new DBColumn(ColumnType.BOOLEAN, \"shared\"));\r\n        columns.add(new DBColumn(ColumnType.BOOLEAN, \"vertical\"));\r\n        columns.add(new DBColumn(ColumnType.BOOLEAN, \"verified\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"suffix\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"groupName\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"groupNo\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"planType\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"planAdmin\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"webAddress\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"emailAddress\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"PhoneNoPrimary\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"PhoneNoSecondary\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"address\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"city\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"state\"));\r\n        columns.add(new DBColumn(ColumnType.STRING, \"zipCode\"));\r\n\r\n        return Collections.unmodifiableList(columns);\r\n    }\r\n}\r\n```\r\nThe database migration is given below:\r\n\r\n```java\r\n@Override\r\n    public long execute(Realm realm, long version) {\r\n        AppDebugLogWriter.writeIntoLog(\"REALM\", \"migration called, current version: \" + version);\r\n        if(version == 1) //InsuranceCard Model has been added in version 2\r\n        {\r\n            Table medicalCardTable = realm.getTable(MedicalInsuranceCard.class);\r\n\r\n            if(medicalCardTable != null)\r\n            {\r\n                AppDebugLogWriter.writeIntoLog(\"REALM\", \"got the medical card table\");\r\n\r\n                for(DBColumn column:MedicalInsuranceCard.getColumns())\r\n                {\r\n                    AppDebugLogWriter.writeIntoLog(\"REALM\", \"adding column: \" + column.getNameOfColumn());\r\n\r\n                    long columnIndex = -1;\r\n                    if(column.getDataTypeOfColumn() == ColumnType.LINK_LIST || column.getDataTypeOfColumn() == ColumnType.LINK)\r\n                    {\r\n                        Table linkedTable = realm.getTable(column.getLinkedToClass());\r\n                        columnIndex = medicalCardTable.addColumnLink(column.getDataTypeOfColumn(), column.getNameOfColumn(), linkedTable);\r\n                    }\r\n                    else\r\n                    {\r\n                        columnIndex = medicalCardTable.addColumn(column.getDataTypeOfColumn(), column.getNameOfColumn());\r\n                    }\r\n\r\n                    if(column.isPrimaryKey())\r\n                    {\r\n                        medicalCardTable.addSearchIndex(columnIndex);\r\n                        medicalCardTable.setPrimaryKey(column.getNameOfColumn());\r\n                    }\r\n                }\r\n            }\r\n            version++;\r\n\r\n            AppDebugLogWriter.writeIntoLog(\"REALM\", \"migrated to version: \" + version);\r\n        }\r\n\r\n        if(version == 2) //Things have been updated\r\n        {\r\n            //Migrate CredntialImage\r\n            Table imageTable = realm.getTable(CredentialImage.class);\r\n            if(imageTable != null)\r\n            {\r\n                long imgIdIndex = imageTable.addColumn(ColumnType.STRING, CredentialImage.PRIMARY_KEY_NAME);\r\n\r\n                for(int i = 0; i < imageTable.size(); i++)\r\n                {\r\n                    String key = UUID.randomUUID().toString();\r\n                    imageTable.setString(imgIdIndex, i, key);\r\n                }\r\n\r\n                imageTable.addSearchIndex(imgIdIndex);\r\n                imageTable.setPrimaryKey(CredentialImage.PRIMARY_KEY_NAME);\r\n            }\r\n\r\n            //Migrate InsuranceCard\r\n            Table medicalTable = realm.getTable(InsuranceCard.class);\r\n            if(medicalTable != null)\r\n            {\r\n                long bOrientationIndex = getIndexForProperty(medicalTable, \"backImageOrientation\");\r\n                long fOrientationIndex = getIndexForProperty(medicalTable, \"frontImageOrientation\");\r\n\r\n                medicalTable.removeColumn(bOrientationIndex);\r\n                medicalTable.removeColumn(fOrientationIndex);\r\n\r\n                long syncIndex = medicalTable.addColumn(ColumnType.BOOLEAN, \"synced\");\r\n                long deleteIndex = medicalTable.addColumn(ColumnType.BOOLEAN, \"deleted\");\r\n\r\n                /*this code was added to test if this makes the MigrationExceptionNeeded due to Field \"issueDate\" not being found go away. But it caused \"Field count does not match - expected 33 but was 34\"*/\r\n                /*boolean issueDateAdded = false;\r\n                long issueDateIndex = getIndexForProperty(medicalTable, \"issueDate\");\r\n                if(issueDateIndex == -1)\r\n                {\r\n                    AppDebugLogWriter.writeIntoLog(\"REALM\", \"issueDate not found in version 2, adding...\");\r\n                    issueDateIndex = medicalTable.addColumn(ColumnType.INTEGER, \"issueDate\");\r\n                    issueDateAdded = true;\r\n                }*/\r\n\r\n                for(int i = 0; i < medicalTable.size(); i++)\r\n                {\r\n                    medicalTable.setBoolean(syncIndex, i, false);\r\n                    medicalTable.setBoolean(deleteIndex, i, false);\r\n\r\n                    /*if(issueDateAdded) {\r\n                        medicalTable.setLong(issueDateIndex, i, 0);\r\n                    }*/\r\n                }\r\n            }\r\n            version++;\r\n            AppDebugLogWriter.writeIntoLog(\"REALM\", \"migrated to version: \" + version);\r\n        }\r\n\r\n        return version;\r\n    }\r\n```\r\nNow when I install the later version of the app I get the error `io.realm.exceptions.RealmMigrationNeededException: Field 'issueDate' not found for Type InsuranceCard`. I have tried installing directly the app with schema version 2 first (so the migration from 1 to 2 can't possibly mess things up) and then install the latest version and still got the same error. I have also tried adding the missing field in migration but that resulted in another exception `io.realm.exceptions.RealmMigrationNeededException: Field count does not match - expected 33 but was 34`"},"comment":{"url":"https://api.github.com/repos/realm/realm-java/issues/comments/159615065","html_url":"https://github.com/realm/realm-java/issues/1826#issuecomment-159615065","issue_url":"https://api.github.com/repos/realm/realm-java/issues/1826","id":159615065,"user":{"login":"iamMehedi","id":3691635,"avatar_url":"https://avatars.githubusercontent.com/u/3691635?v=3","gravatar_id":"","url":"https://api.github.com/users/iamMehedi","html_url":"https://github.com/iamMehedi","followers_url":"https://api.github.com/users/iamMehedi/followers","following_url":"https://api.github.com/users/iamMehedi/following{/other_user}","gists_url":"https://api.github.com/users/iamMehedi/gists{/gist_id}","starred_url":"https://api.github.com/users/iamMehedi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iamMehedi/subscriptions","organizations_url":"https://api.github.com/users/iamMehedi/orgs","repos_url":"https://api.github.com/users/iamMehedi/repos","events_url":"https://api.github.com/users/iamMehedi/events{/privacy}","received_events_url":"https://api.github.com/users/iamMehedi/received_events","type":"User","site_admin":false},"created_at":"2015-11-25T14:01:09Z","updated_at":"2015-11-25T14:01:09Z","body":"@kneth I'll upgrade to the latest version of Realm and will let you know if that fixes it. "}}