{"action":"created","issue":{"url":"https://api.github.com/repos/realm/realm-java/issues/2498","repository_url":"https://api.github.com/repos/realm/realm-java","labels_url":"https://api.github.com/repos/realm/realm-java/issues/2498/labels{/name}","comments_url":"https://api.github.com/repos/realm/realm-java/issues/2498/comments","events_url":"https://api.github.com/repos/realm/realm-java/issues/2498/events","html_url":"https://github.com/realm/realm-java/issues/2498","id":141840859,"number":2498,"title":"Realm Migration","user":{"login":"DevikaSrinivasan","id":16413369,"avatar_url":"https://avatars.githubusercontent.com/u/16413369?v=3","gravatar_id":"","url":"https://api.github.com/users/DevikaSrinivasan","html_url":"https://github.com/DevikaSrinivasan","followers_url":"https://api.github.com/users/DevikaSrinivasan/followers","following_url":"https://api.github.com/users/DevikaSrinivasan/following{/other_user}","gists_url":"https://api.github.com/users/DevikaSrinivasan/gists{/gist_id}","starred_url":"https://api.github.com/users/DevikaSrinivasan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DevikaSrinivasan/subscriptions","organizations_url":"https://api.github.com/users/DevikaSrinivasan/orgs","repos_url":"https://api.github.com/users/DevikaSrinivasan/repos","events_url":"https://api.github.com/users/DevikaSrinivasan/events{/privacy}","received_events_url":"https://api.github.com/users/DevikaSrinivasan/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/realm/realm-java/labels/S:Waiting%20For%20User","name":"S:Waiting For User","color":"ededed"},{"url":"https://api.github.com/repos/realm/realm-java/labels/T:Help","name":"T:Help","color":"cc317c"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":19,"created_at":"2016-03-18T11:27:20Z","updated_at":"2016-03-22T08:19:54Z","closed_at":"2016-03-22T08:19:54Z","body":"Hi,\r\n\r\nMy Previous released version has the following migration code,\r\n\r\nFirst Version:\r\n**Migration.Class**\r\n```\r\npublic class Migration implements RealmMigration {\r\n\r\n    public void migrate(final DynamicRealm realm, long oldVersion, long newVersion) {\r\n        RealmSchema schema = realm.getSchema();\r\n        if (oldVersion == 0) {\r\n            schema.get(\"MesRecherchesBean\")\r\n                    .addField(\"trouver_unbien_type\", String.class)\r\n                    .addField(\"trouver_unbien_uuid\", String.class)\r\n                    .addField(\"trouver_unbien_name\", String.class)\r\n                    .addField(\"trouver_unbien_nb\", String.class)\r\n                    .addField(\"trouver_unbien_newnb\", String.class);\r\n            schema.get(\"RecentSearchBean\")\r\n                    .addField(\"trouver_unbien_type\", String.class);\r\n            oldVersion++;\r\n        }\r\n    }\r\n}\r\n```\r\n\r\n**Application.Class:**\r\n```\r\nRealmConfiguration config1 = new RealmConfiguration.Builder(this)\r\n                .schemaVersion(0)\r\n                .migration(new Migration())\r\n                .build();\r\n\r\n        realm = Realm.getInstance(config1); // Automatically run migration if needed\r\n        realm.close();\r\n```\r\n\r\nSecond Version:\r\n```\r\npublic class Migration implements RealmMigration {\r\n\r\n    public void migrate(final DynamicRealm realm, long oldVersion, long newVersion) {\r\n        RealmSchema schema = realm.getSchema();\r\n        if (oldVersion == 0) {\r\n            schema.get(\"MesRecherchesBean\")\r\n                    .addField(\"trouver_unbien_type\", String.class)\r\n                    .addField(\"trouver_unbien_uuid\", String.class)\r\n                    .addField(\"trouver_unbien_name\", String.class)\r\n                    .addField(\"trouver_unbien_nb\", String.class)\r\n                    .addField(\"trouver_unbien_newnb\", String.class);\r\n            schema.get(\"RecentSearchBean\")\r\n                    .addField(\"trouver_unbien_type\", String.class);\r\n            oldVersion++;\r\n        }\r\n        if (oldVersion == 1) {\r\n            schema.get(\"MesNotificationBean\")\r\n                    .addField(\"notificationUuid\",String.class);\r\n            schema.get(\"AppartmentOpacityBean\")\r\n                    .addField(\"appartmentOpacityId\", String.class);\r\n            oldVersion++;\r\n        }\r\n    }\r\n}\r\n```\r\n**Application.Class:**\r\n```\r\nRealmConfiguration config1 = new RealmConfiguration.Builder(this)\r\n                .schemaVersion(0)\r\n                .migration(new Migration())\r\n                .build();\r\n\r\n        realm = Realm.getInstance(config1); // Automatically run migration if needed\r\n        realm.close();\r\n```\r\n\r\n********************************************\r\n\r\nDownloaded playstore version and added few data to the database. Then I created new apk and then installed to my device. So it creates null pointer exception in the Migration.class in this line  schema.get(\"MesNotificationBean\")\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/realm/realm-java/issues/comments/199694883","html_url":"https://github.com/realm/realm-java/issues/2498#issuecomment-199694883","issue_url":"https://api.github.com/repos/realm/realm-java/issues/2498","id":199694883,"user":{"login":"emanuelez","id":473050,"avatar_url":"https://avatars.githubusercontent.com/u/473050?v=3","gravatar_id":"","url":"https://api.github.com/users/emanuelez","html_url":"https://github.com/emanuelez","followers_url":"https://api.github.com/users/emanuelez/followers","following_url":"https://api.github.com/users/emanuelez/following{/other_user}","gists_url":"https://api.github.com/users/emanuelez/gists{/gist_id}","starred_url":"https://api.github.com/users/emanuelez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/emanuelez/subscriptions","organizations_url":"https://api.github.com/users/emanuelez/orgs","repos_url":"https://api.github.com/users/emanuelez/repos","events_url":"https://api.github.com/users/emanuelez/events{/privacy}","received_events_url":"https://api.github.com/users/emanuelez/received_events","type":"User","site_admin":false},"created_at":"2016-03-22T08:19:53Z","updated_at":"2016-03-22T08:19:53Z","body":"I will now close this issue. Please feel free to open a new one if you run into more issues."}}