# Error with self-migrating stack - Chapter 6

**URL:** <https://forums.kodeco.com/t/error-with-self-migrating-stack-chapter-6/41688>\
**Category:** Core Data by Tutorials\
**Created:** [April 17, 2018, 5:36pm UTC](https://forums.kodeco.com/t/error-with-self-migrating-stack-chapter-6/41688 "2018-04-17T17:36:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![barrera](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/barrera/32/102075_2.png) [@barrera](https://forums.kodeco.com/u/barrera)\
**Post date:** [April 17, 2018, 5:36pm UTC](https://forums.kodeco.com/t/error-with-self-migrating-stack-chapter-6/41688/1 "2018-04-17T17:36:12Z")

</div>

I’ve a problem with this part of the book, my code is correct (I’ve even tried it with the book’s source code) and I’m getting always the fatalError(“Can only handle migrations to version 4!”). My DB is not empty because I first added info with version 2. I checked the error and the problem seems that .isVersion# always is false.

Does anyone know what’s the problem?

I’m reading the last version of the book and currently using Xcode 9.3.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![syedfa](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/syedfa/32/101500_2.png) [@syedfa](https://forums.kodeco.com/u/syedfa)\
**Post date:** [April 20, 2018, 4:16am UTC](https://forums.kodeco.com/t/error-with-self-migrating-stack-chapter-6/41688/2 "2018-04-20T04:16:36Z")

</div>

@barrera Thanks very much for your question!

Is it possible for you to show us some of your code which is causing the error?

---

<div class="post-metadata">

**Author:** ![barrera](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/barrera/32/102075_2.png) [@barrera](https://forums.kodeco.com/u/barrera)\
**Post date:** [April 20, 2018, 3:27pm UTC](https://forums.kodeco.com/t/error-with-self-migrating-stack-chapter-6/41688/3 "2018-04-20T15:27:09Z")

</div>

My code is exactly as the one provided with the book, both have the same problem.

I’m guessing the problem is between these parts of the code:

I’m getting always this fatal error, because currentModel.isVersion4 is always false.

```
func performMigration() {
    if !currentModel.isVersion4 {
      fatalError("Can only handle migrations to version 4!")
    }
}

```

I made a test printing the values of currentModel.isVersion1, 2, 3, and 4, and I’m getting always false

The code for isVersion# is this:

```
var isVersion4: Bool {
    return self == type(of: self).version4
}

```

The class var version4 is this:

```
class var version4: NSManagedObjectModel {
    return uncloudNotesModel(named: "UnCloudNotesDataModel v4")
}

```

And the method uncloudNotesModel is this:

```
class func uncloudNotesModel(named modelName: String) -> NSManagedObjectModel {
    let model = modelURLs(in: "UnCloudNotesDataModel")
      .filter { $0.lastPathComponent == "\(modelName).mom" }
      .first
      .flatMap(NSManagedObjectModel.init)

    print(modelURLs(in: "UnCloudNotesDataModel"))

    return model ?? NSManagedObjectModel()
}

```

Hope it helps 😕

---

<div class="post-metadata">

**Author:** ![sgerrard](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/sgerrard/32/93812_2.png) [@sgerrard](https://forums.kodeco.com/u/sgerrard)\
**Post date:** [July 12, 2018, 2:44am UTC](https://forums.kodeco.com/t/error-with-self-migrating-stack-chapter-6/41688/4 "2018-07-12T02:44:07Z")

</div>

It sounds like you need to set which version is the current version. This is set to version 4:

![image](https://raywenderlich-com-v3-forums.s3.amazonaws.com/original/3X/5/7/577d7ca58c015124b47da0e1a073859e41b0b241.png)

If you click on one of the versions, then pick the file inspector over on the right, you can see a dropdown that lets you set which version is current:

![image](https://raywenderlich-com-v3-forums.s3.amazonaws.com/original/3X/9/6/969eb1f73d395e721787a72c316af0c79d45c73f.png)

---

<div class="post-metadata">

**Author:** ![system](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@system](https://forums.kodeco.com/u/system)\
**Post date:** [October 1, 2018, 9:44am UTC](https://forums.kodeco.com/t/error-with-self-migrating-stack-chapter-6/41688/5 "2018-10-01T09:44:44Z")

</div>

Closed on October 1, 2018, 9:44am UTC

This topic was automatically closed after 166 days. New replies are no longer allowed.
