{"action":"created","issue":{"url":"https://api.github.com/repos/realm/realm-java/issues/1825","labels_url":"https://api.github.com/repos/realm/realm-java/issues/1825/labels{/name}","comments_url":"https://api.github.com/repos/realm/realm-java/issues/1825/comments","events_url":"https://api.github.com/repos/realm/realm-java/issues/1825/events","html_url":"https://github.com/realm/realm-java/issues/1825","id":118788430,"number":1825,"title":"io.realm.exceptions.RealmMigrationNeededException: Field count does not match - expected x but was y (0.85.1)","user":{"login":"ashemah","id":461490,"avatar_url":"https://avatars.githubusercontent.com/u/461490?v=3","gravatar_id":"","url":"https://api.github.com/users/ashemah","html_url":"https://github.com/ashemah","followers_url":"https://api.github.com/users/ashemah/followers","following_url":"https://api.github.com/users/ashemah/following{/other_user}","gists_url":"https://api.github.com/users/ashemah/gists{/gist_id}","starred_url":"https://api.github.com/users/ashemah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ashemah/subscriptions","organizations_url":"https://api.github.com/users/ashemah/orgs","repos_url":"https://api.github.com/users/ashemah/repos","events_url":"https://api.github.com/users/ashemah/events{/privacy}","received_events_url":"https://api.github.com/users/ashemah/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":5,"created_at":"2015-11-25T08:54:20Z","updated_at":"2015-11-25T09:12:07Z","closed_at":null,"body":"Hi all, since upgrading to the latest version of realm (0.85.1) my migrations are broken and it is driving me crazy.\r\n\r\n    io.realm.exceptions.RealmMigrationNeededException: Field count does not match - expected x but was y\r\n\r\nI keep getting the exception above even though I have a realm migration specified in the config that covers the migration. I have tried every combination of manually handling the RealmMigrationNeededException and migrating the realm or setting a migration in the config and I still get either the error above or a migration needed error or similar.\r\n\r\nAlso, I have added @Required to all of my String fields and I was originally running on 0.80.1 if that helps.\r\n\r\nDoes anyone have an idea why this could be happening?\r\n\r\nMy migration stuff in my Application.onCreate()\r\n\r\n```java\r\n        RealmConfiguration config0 = new RealmConfiguration.Builder(this)\r\n                .schemaVersion(4)\r\n                .migration(new Migration())\r\n                .build();\r\n\r\n        try {\r\n            Realm realm1 = Realm.getInstance(config0);\r\n        }\r\n        catch (RealmMigrationNeededException e) {\r\n            Realm.migrateRealm(config0, new Migration());\r\n        }\r\n\r\n        Realm.setDefaultConfiguration(config0);\r\n\r\n      // If I call Realm realm1 = Realm.getDefaultInstance() here it will still explode.\r\n```\r\n\r\nMy migration\r\n\r\n```java\r\npackage com.foo.bar;\r\n\r\nimport com.foo.bar.data.Answer;\r\nimport com.foo.bar.data.AnswerSet;\r\nimport com.foo.bar.data.Survey;\r\nimport com.foo.bar.data.User;\r\n\r\nimport io.realm.Realm;\r\nimport io.realm.RealmMigration;\r\nimport io.realm.internal.ColumnType;\r\nimport io.realm.internal.Table;\r\n\r\npublic class Migration implements RealmMigration {\r\n\r\n    @Override\r\n    public long execute(Realm realm, long version) {\r\n\r\n        if (version == 0) {\r\n            Table locationTable = realm.getTable(User.class);\r\n            locationTable.addColumn(ColumnType.STRING, \"pushToken\");\r\n\r\n            Table answerSetTable = realm.getTable(AnswerSet.class);\r\n            answerSetTable.addColumn(ColumnType.INTEGER, \"firstReminderRequestCode\");\r\n            answerSetTable.addColumn(ColumnType.INTEGER, \"secondReminderRequestCode\");\r\n            answerSetTable.addColumn(ColumnType.INTEGER, \"firstReminderTimestamp\");\r\n            answerSetTable.addColumn(ColumnType.INTEGER, \"secondReminderTimestamp\");\r\n\r\n            version++;\r\n        }\r\n\r\n        if (version == 1) {\r\n            Table surveyTable = realm.getTable(Survey.class);\r\n            surveyTable.addColumn(ColumnType.BOOLEAN, \"scheduleAllowMonday\");\r\n            surveyTable.addColumn(ColumnType.BOOLEAN, \"scheduleAllowTuesday\");\r\n            surveyTable.addColumn(ColumnType.BOOLEAN, \"scheduleAllowWednesday\");\r\n            surveyTable.addColumn(ColumnType.BOOLEAN, \"scheduleAllowThursday\");\r\n            surveyTable.addColumn(ColumnType.BOOLEAN, \"scheduleAllowFriday\");\r\n            surveyTable.addColumn(ColumnType.BOOLEAN, \"scheduleAllowSaturday\");\r\n            surveyTable.addColumn(ColumnType.BOOLEAN, \"scheduleAllowSunday\");\r\n\r\n            version++;\r\n        }\r\n\r\n        if (version == 2) {\r\n            Table answerTable = realm.getTable(Answer.class);\r\n            answerTable.addColumn(ColumnType.INTEGER, \"reactionTimeMs\");\r\n\r\n            version++;\r\n        }\r\n\r\n        if (version == 3) {\r\n           // blank just for testing purposes - I didn't actually change the model and this error was still happening when this migration was not here.\r\n            version++;\r\n        }\r\n\r\n        return version;\r\n    }\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/realm/realm-java/issues/comments/159543613","html_url":"https://github.com/realm/realm-java/issues/1825#issuecomment-159543613","issue_url":"https://api.github.com/repos/realm/realm-java/issues/1825","id":159543613,"user":{"login":"ashemah","id":461490,"avatar_url":"https://avatars.githubusercontent.com/u/461490?v=3","gravatar_id":"","url":"https://api.github.com/users/ashemah","html_url":"https://github.com/ashemah","followers_url":"https://api.github.com/users/ashemah/followers","following_url":"https://api.github.com/users/ashemah/following{/other_user}","gists_url":"https://api.github.com/users/ashemah/gists{/gist_id}","starred_url":"https://api.github.com/users/ashemah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ashemah/subscriptions","organizations_url":"https://api.github.com/users/ashemah/orgs","repos_url":"https://api.github.com/users/ashemah/repos","events_url":"https://api.github.com/users/ashemah/events{/privacy}","received_events_url":"https://api.github.com/users/ashemah/received_events","type":"User","site_admin":false},"created_at":"2015-11-25T09:12:07Z","updated_at":"2015-11-25T09:12:07Z","body":"Ok thanks, I'll give it a shot."}}