project-imas / encrypted-core-data

v2.0 - iOS Core Data encrypted SQLite store using SQLCipher
Other
785 stars 236 forks source link

Migration fails due to Many to Many relation tables are already exist #313

Open mailmemani opened 5 years ago

mailmemani commented 5 years ago

I have introduced a new column in a table A which has MANY to MANY relations with table B.

Lightweight Migration is failing when I modify the table A (Which has Many to Many relations)

Log says while migrating, could not prepare statement: table ecd_A_B already exists

Thanks

StacyCC commented 5 years ago

Hi Mailmemani,

I face the same problem for light weight migration. And I found that "tableNameForPreviousRelationship" and "tableNameForRelationship" are different. In "tableNameForPreviousRelationship" use sort but "tableNameForRelationship" does not. This may cause the name for table be different.

I try to remove the sort in function "tableNameForPreviousRelationship" NSArray *names = @[([relationship renamingIdentifier] ? [relationship renamingIdentifier] : [relationship name]), ([inverse renamingIdentifier] ? [inverse renamingIdentifier] : [inverse name])];

This seems work for me. Thanks.

mailmemani commented 5 years ago

Hi StacyCC,

Thanks, I tried to interchange the tableNameForRelationship function table names array values.

Like below NSArray *names = @[[inverse name], [relationship name]];

This also works fine for me. And I tried to remove the sort function from tableNameForPreviousRelationship even that works fine for me.

Thanks.