{"action":"created","issue":{"url":"https://api.github.com/repos/realm/realm-java/issues/2819","repository_url":"https://api.github.com/repos/realm/realm-java","labels_url":"https://api.github.com/repos/realm/realm-java/issues/2819/labels{/name}","comments_url":"https://api.github.com/repos/realm/realm-java/issues/2819/comments","events_url":"https://api.github.com/repos/realm/realm-java/issues/2819/events","html_url":"https://github.com/realm/realm-java/issues/2819","id":155138284,"number":2819,"title":"\"Index not defined for existing Realm file\" error while performing migration.","user":{"login":"vladiulianbogdan","id":2605114,"avatar_url":"https://avatars.githubusercontent.com/u/2605114?v=3","gravatar_id":"","url":"https://api.github.com/users/vladiulianbogdan","html_url":"https://github.com/vladiulianbogdan","followers_url":"https://api.github.com/users/vladiulianbogdan/followers","following_url":"https://api.github.com/users/vladiulianbogdan/following{/other_user}","gists_url":"https://api.github.com/users/vladiulianbogdan/gists{/gist_id}","starred_url":"https://api.github.com/users/vladiulianbogdan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vladiulianbogdan/subscriptions","organizations_url":"https://api.github.com/users/vladiulianbogdan/orgs","repos_url":"https://api.github.com/users/vladiulianbogdan/repos","events_url":"https://api.github.com/users/vladiulianbogdan/events{/privacy}","received_events_url":"https://api.github.com/users/vladiulianbogdan/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/realm/realm-java/labels/T:Bug","name":"T:Bug","color":"eb6420"}],"state":"closed","locked":false,"assignee":{"login":"stk1m1","id":16395854,"avatar_url":"https://avatars.githubusercontent.com/u/16395854?v=3","gravatar_id":"","url":"https://api.github.com/users/stk1m1","html_url":"https://github.com/stk1m1","followers_url":"https://api.github.com/users/stk1m1/followers","following_url":"https://api.github.com/users/stk1m1/following{/other_user}","gists_url":"https://api.github.com/users/stk1m1/gists{/gist_id}","starred_url":"https://api.github.com/users/stk1m1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stk1m1/subscriptions","organizations_url":"https://api.github.com/users/stk1m1/orgs","repos_url":"https://api.github.com/users/stk1m1/repos","events_url":"https://api.github.com/users/stk1m1/events{/privacy}","received_events_url":"https://api.github.com/users/stk1m1/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/realm/realm-java/milestones/9","html_url":"https://github.com/realm/realm-java/milestones/0.91","labels_url":"https://api.github.com/repos/realm/realm-java/milestones/9/labels","id":1716901,"number":9,"title":"0.91","description":null,"creator":{"login":"cmelchior","id":406066,"avatar_url":"https://avatars.githubusercontent.com/u/406066?v=3","gravatar_id":"","url":"https://api.github.com/users/cmelchior","html_url":"https://github.com/cmelchior","followers_url":"https://api.github.com/users/cmelchior/followers","following_url":"https://api.github.com/users/cmelchior/following{/other_user}","gists_url":"https://api.github.com/users/cmelchior/gists{/gist_id}","starred_url":"https://api.github.com/users/cmelchior/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cmelchior/subscriptions","organizations_url":"https://api.github.com/users/cmelchior/orgs","repos_url":"https://api.github.com/users/cmelchior/repos","events_url":"https://api.github.com/users/cmelchior/events{/privacy}","received_events_url":"https://api.github.com/users/cmelchior/received_events","type":"User","site_admin":false},"open_issues":8,"closed_issues":25,"state":"open","created_at":"2016-04-19T12:49:40Z","updated_at":"2016-05-18T16:32:47Z","due_on":null,"closed_at":null},"comments":3,"created_at":"2016-05-16T22:38:14Z","updated_at":"2016-05-18T19:51:21Z","closed_at":"2016-05-18T16:32:47Z","body":"Hello,\r\n\r\nI'm using Realm 0.90.1.\r\n\r\nI'm trying to perform a migration in which I want to create two more tables. One of them has a @PrimaryKey.\r\n\r\nI've tried the manual way like this:\r\n\r\nAnd the migration looks like this:\r\n\r\n```\r\n          public void migrate(DynamicRealm realm, long oldVersion, long newVersion) {\r\n\t\tRealmSchema schema = realm.getSchema();\r\n\r\n\t\tif (oldVersion == 0) {\r\n\t\t\tschema.create(\"Table1\").addField(\"myid\", long.class)\r\n\t\t\t\t\t.addField(\"test\", boolean.class)\r\n\t\t\t\t\t.addPrimaryKey(\"myid\");\r\n\r\n\t\t\tschema.create(\"Table2\").addField(\"wID\", int.class)\r\n\t\t\t\t.addField(\"uID\", int.class)\r\n\t\t\t\t.addField(\"ts\", long.class)\r\n\t\t\t\t.addField(\"type\", String.class);\r\n\r\n\t\t\toldVersion++;\r\n\t\t}\r\n```\r\n\r\nMy applications crashes with the following exception:\r\n\r\n`                                                                         \r\nProcess: com.vectorwatch.android, PID: 22182 java.lang.RuntimeException: Unable to create application com.android.tools.fd.runtime.BootstrapApplication: io.realm.exceptions.RealmMigrationNeededException: RealmMigration must be provided\r\n                                                                             at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4664)`\r\n\r\nI've dived deeper in Realm code and I've saw that an exception is thrown with the following detailsMessage:\r\n\r\n`Index not defined for field myid in existing Realm file. Either set @Index or migrate using io.realm.internal.Table.removeSearchIndex().\r\n`\r\n\r\nSo I assumed that I should call also addIndex() in the migration. This did the trick, but this is was kind of annoying. From the Realm documentation, I see that \"(the annotation @PrimaryKey implicitly sets the annotation @Index)\". The javadoc of the addPrimaryKey method says:\r\n\r\n`\r\n     * Adds a primary key to a given field. This is the same as adding the {@link io.realm.annotations.PrimaryKey} annotation on the field.\r\n`\r\n\r\nSo I assumed that addPrimaryKey() also adds an Index. It is nowhere mentioned that when performing a migration, you should call addIndex() when you have an addPrimaryKey().\r\n\r\nCan I make a pull request to add this use case in your Migration example app? Also please tell if I can help anymore you with this issue.\r\n\r\n\r\nThank you very much for this great framework!"},"comment":{"url":"https://api.github.com/repos/realm/realm-java/issues/comments/220138336","html_url":"https://github.com/realm/realm-java/issues/2819#issuecomment-220138336","issue_url":"https://api.github.com/repos/realm/realm-java/issues/2819","id":220138336,"user":{"login":"vladiulianbogdan","id":2605114,"avatar_url":"https://avatars.githubusercontent.com/u/2605114?v=3","gravatar_id":"","url":"https://api.github.com/users/vladiulianbogdan","html_url":"https://github.com/vladiulianbogdan","followers_url":"https://api.github.com/users/vladiulianbogdan/followers","following_url":"https://api.github.com/users/vladiulianbogdan/following{/other_user}","gists_url":"https://api.github.com/users/vladiulianbogdan/gists{/gist_id}","starred_url":"https://api.github.com/users/vladiulianbogdan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vladiulianbogdan/subscriptions","organizations_url":"https://api.github.com/users/vladiulianbogdan/orgs","repos_url":"https://api.github.com/users/vladiulianbogdan/repos","events_url":"https://api.github.com/users/vladiulianbogdan/events{/privacy}","received_events_url":"https://api.github.com/users/vladiulianbogdan/received_events","type":"User","site_admin":false},"created_at":"2016-05-18T19:51:21Z","updated_at":"2016-05-18T19:51:21Z","body":"Thank you, guys!"}}