{"action":"created","issue":{"url":"https://api.github.com/repos/realm/realm-java/issues/1173","labels_url":"https://api.github.com/repos/realm/realm-java/issues/1173/labels{/name}","comments_url":"https://api.github.com/repos/realm/realm-java/issues/1173/comments","events_url":"https://api.github.com/repos/realm/realm-java/issues/1173/events","html_url":"https://github.com/realm/realm-java/issues/1173","id":83931119,"number":1173,"title":"Database migration process went harder when creating new model classes","user":{"login":"tmeunier","id":10448238,"avatar_url":"https://avatars.githubusercontent.com/u/10448238?v=3","gravatar_id":"","url":"https://api.github.com/users/tmeunier","html_url":"https://github.com/tmeunier","followers_url":"https://api.github.com/users/tmeunier/followers","following_url":"https://api.github.com/users/tmeunier/following{/other_user}","gists_url":"https://api.github.com/users/tmeunier/gists{/gist_id}","starred_url":"https://api.github.com/users/tmeunier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tmeunier/subscriptions","organizations_url":"https://api.github.com/users/tmeunier/orgs","repos_url":"https://api.github.com/users/tmeunier/repos","events_url":"https://api.github.com/users/tmeunier/events{/privacy}","received_events_url":"https://api.github.com/users/tmeunier/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/realm/realm-java/labels/Pending","name":"Pending","color":"ededed"},{"url":"https://api.github.com/repos/realm/realm-java/labels/support","name":"support","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-06-02T09:15:52Z","updated_at":"2015-06-04T09:16:43Z","closed_at":null,"body":"Hi,\r\nI've ran into an problem after updating from Realm 0.80.1 to 0.80.3.\r\n\r\n### 1. The goal is to migrate my database with new model entities\r\nI have to add model entities in my app within each iteration of my app. These entities have many columns (5 to 15).\r\nI **cannot** simple break my databases (they contain hundreds of records).\r\n\r\n### 2. The migration was working...\r\nMy migration process was simple: when adding a new class, the table and columns were created when calling ```realm.createObject( clazz )```\r\n\r\n### 3. ...until upgrade\r\nAfter updating Realm my code throws ```java.lang.ArrayIndexOutOfBoundsException: Table has no columns: class_xxx```\r\n\r\n### 4. I've find out why\r\nThe code that was initialising the table scheme is not executed, instead a simple getTable which creates an EMPTY table\r\n```java\r\n\r\npublic <E extends RealmObject> E createObject(Class<E> clazz) {\r\n  Table table = getTable(clazz);\r\n  long rowIndex = table.addEmptyRow(); <==== crash is here, because the is no column in the table!\r\n  return get(clazz, rowIndex);\r\n}\r\n```\r\n\r\nThe only createTable ever executed is in ```initializeRealm```, but it's only executed when there is no version on the database... which causes me trouble (as my database version is 2 in the present case)\r\n```java\r\n// Create and validate table\r\nif (version == UNVERSIONED) {\r\n     proxyMediator.createTable(modelClass, realm.transaction);\r\n}\r\n```\r\n\r\n### So my solutions are:\r\n- use java.reflect to call this \"createTable\" directly (that will break if you change a thing)\r\n- add every column of every new class (~100 columns)  :/\r\n\r\n\r\nI know you are not working on migration process, but in my opinion this is a regression. A simple \"createTableIfNonExistent\" method would do the trick until a new migration system is up.\r\nI'd be happy with any suggestion, feedback."},"comment":{"url":"https://api.github.com/repos/realm/realm-java/issues/comments/108799137","html_url":"https://github.com/realm/realm-java/issues/1173#issuecomment-108799137","issue_url":"https://api.github.com/repos/realm/realm-java/issues/1173","id":108799137,"user":{"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},"created_at":"2015-06-04T09:16:43Z","updated_at":"2015-06-04T09:16:43Z","body":"We would love any and all comments about the API, so please share them :)\r\nYou can send them to help@realm.io if you don't want to post them here."}}