Updating primary key in migration
See original GitHub issueHello I’m new in having a problem in order to do migration I want to update the primary key of an object and create new object in new created schema
here is my code of what I trying to do
error message : Cannot modify primary key after creation
const realm = new Realm({
schema: [profileSchema, postsSchema, billSchema, billItemsSchema, postImages],
schemaVersion: 1,
migration: function(oldRealm, newRealm) {
if (oldRealm.schemaVersion < 1) {
let oldObjects = oldRealm.objects('posts'),
newObjects = newRealm.objects('posts'),
arr = [];
for (let i = 0; i < oldObjects.length; i++) {
let image1 = oldObjects[i].image1,
image2 = oldObjects[i].image2,
image3 = oldObjects[i].image3,
image4 = oldObjects[i].image4;
newObjects[i].id = oldObjects[i].key;
arr.concat(image1, image2, image3, image4);
realm.write(() => {
let posts = realm.objects('posts')[i];
arr.map((val, x) => {
posts.images.push({id: oldObjects[i].key + x, image: val});
})
})
}
}
}
});
Anybody can guide can help me to solve this
Thanks in advance
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How to change primary key in laravel migration - Stack Overflow
I'm trying to change the primary key on a table so I can use an other column as foreign key too. Here's the...
Read more >ALTER PRIMARY KEY | CockroachDB Docs
To change an existing primary key without creating a secondary index from that primary key, use DROP CONSTRAINT ... PRIMARY KEY / ADD...
Read more >Yet another Postgres migration: updating primary key type to ...
You have a table with a primary key constraint on a single integer column (let it be id ) and number of records...
Read more >Changing an SQL Server primary key in Doctrine Migrations
I recently came across a rather weird quirk when trying to change a primary key in Sql Server using Doctrine Migrations: you need...
Read more >defining primary keys in migration - Laracasts
Hi, I have implemented a table for letting twitter like following users. Here is the migration: Schema::create('follows', function (Blueprint $table) ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This was fixed by https://github.com/realm/realm-object-store/pull/471, which has been pulled in here.
Hi there is a bug and we are working on fixing it for this issue.