Text

Index name length error in Rails migrations using SQLite

When trying to process a rename_column database migration, I ran into the following error after running rake db:migrate:

Index name 'temp_index_altered_long_class_name_on_even_longer_class_name_id' on table 'altered_long_class_name' is too long; the limit is 64 characters

This is an issue with index name length when using sqlite. A simple fix is to remove the index prior to renaming the column, then add it back in afterwards, as follows:

remove_index :long_class_name, [:even_longer_class_name_id]
rename_column :long_class_name, :original_name, :new_name
add_index :long_class_name, [:even_longer_class_name_id], :name => "index_long_class_name_on_even_longer_class_name_id"
Text

Core Data Migration and Versioning

Yep, another Core Data post. Hat tip to Jeff LaMarche for the solution on this one.

After adding a new data model version, then moving some furniture around and adding a few new bits and bobs, I hit Build & Go and was hit with the fantastically detailed error:

Can't merge models with two different entities named 'SuckItBiatch'

Head on over to Jeff’s post for the full explanation of what’s going on here but to cut a long story short, there’s an issue with how the .momd bundle works in tandem with Apple’s template code.

Replace the standard -managedObjectModel method with the following, and as long as all other prerequisite pieces are in order you should be fine.

- (NSManagedObjectModel *)managedObjectModel {
    
    if (managedObjectModel != nil) {
        return managedObjectModel;
    }
    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"YourAppName" ofType:@"momd"];
    NSURL *momURL = [NSURL fileURLWithPath:path];
    managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:momURL];
       
    return managedObjectModel;
}