gpt4 book ai didi

core-data - 核心数据异常 : SQLite "no such column" error after adding a new attribute to an entity

转载 作者:行者123 更新时间:2023-12-03 17:30:53 28 4
gpt4 key购买 nike

将名为“localFilePath”的字符串属性添加到名为 GenericAttachment 的核心数据实体后,当我们尝试映射一组这些对象时,我们开始收到异常。

我们的几个实体与 GenericAttachment 的无序集合具有称为“附件”的多对多关系。

这些实体之一称为InspectionMO。 GenericAttatchment 与InspectionMO 有一对多的关系“检查”(不是“检查”,哎呀)。当我们得到一个InspectionMO的附件并尝试映射它们时,我们得到以下异常:

NSInternalInconsistencyException
I/O error for database at /Users/justingarcia/Library/Developer/CoreSimulator/Devices/D075B44C-4F54-4703-8817-3DC4A6E7314E/data/Containers/Data/Application/F425E5AC-C215-4BE8-93DB-A3E6C48C83C4/Library/Application Support/Procore/Procore. SQLite error code:1, 'no such column: t1.Z_55ATTACHMENTS5'

这是异常堆栈跟踪:
#0  0x000000010c94f705 in objc_exception_throw ()
#1 0x000000010e928f00 in -[NSSQLiteConnection prepareSQLStatement:] ()
#2 0x000000010ea99305 in -[NSSQLiteConnection selectRowsWithStatement:cached:] ()
#3 0x000000010e941d0b in newFetchedRowsForFetchPlan_MT ()
#4 0x000000010eb6e574 in _newFetchedPKsForRelationshipFaultRequest ()
#5 0x000000010eb6efba in _executeNewValuesForRelationshipFaultRequest ()
#6 0x000000010ead19a2 in -[NSSQLRelationshipFaultRequestContext executeRequestCore:] ()
#7 0x000000010eb40a00 in -[NSSQLStoreRequestContext executeRequestUsingConnection:] ()
#8 0x000000010eb14e5b in __52-[NSSQLDefaultConnectionManager handleStoreRequest:]_block_invoke ()
#9 0x000000011b25f602 in _dispatch_client_callout ()
#10 0x000000011b26d653 in _dispatch_lane_barrier_sync_invoke_and_complete ()
#11 0x000000010eb14d40 in -[NSSQLDefaultConnectionManager handleStoreRequest:] ()
#12 0x000000010eb1cbb4 in -[NSSQLCoreDispatchManager routeStoreRequest:] ()
#13 0x000000010ea61515 in -[NSSQLCore dispatchRequest:withRetries:] ()
#14 0x000000010ea5cdaa in -[NSSQLCore _newValuesForRelationship:forObjectWithID:withContext:error:] ()
#15 0x000000010e97a8cb in -[NSSQLCore newValueForRelationship:forObjectWithID:withContext:error:] ()
#16 0x000000010ea449d9 in __110-[NSPersistentStoreCoordinator(_NSInternalMethods) newValueForRelationship:forObjectWithID:withContext:error:]_block_invoke ()
#17 0x000000010ea39437 in -[NSPersistentStoreCoordinator _routeLightweightBlock:toStore:] ()
#18 0x000000010e97a7f7 in -[NSPersistentStoreCoordinator(_NSInternalMethods) newValueForRelationship:forObjectWithID:withContext:error:] ()
#19 0x000000010ea0b89e in __107-[NSManagedObjectContext(_NestedContextSupport) newValueForRelationship:forObjectWithID:withContext:error:]_block_invoke ()
#20 0x000000010e972108 in internalBlockToNSManagedObjectContextPerform ()
#21 0x000000011b25f602 in _dispatch_client_callout ()
#22 0x000000011b26d653 in _dispatch_lane_barrier_sync_invoke_and_complete ()
#23 0x000000010e972074 in _perform ()
#24 0x000000010e972c37 in -[NSManagedObjectContext(_NestedContextSupport) newValueForRelationship:forObjectWithID:withContext:error:] ()
#25 0x000000010e97a421 in -[NSFaultHandler retainedFulfillAggregateFaultForObject:andRelationship:withContext:] ()
#26 0x000000010e9a621e in -[_NSFaultingMutableSet willReadWithContents:] ()
#27 0x000000010e94e6a6 in -[_NSFaultingMutableSet count] ()
#28 0x000000011a9e9bdd in protocol witness for Collection.count.getter in conformance Set<A> ()
#29 0x000000011a8726d1 in Collection.map<A>(_:) ()
#30 0x00000001162ad07e in ObjectImportHelper.copyToMany<A>(_:to:cache:deleteMissing:onCopy:) at /Users/justingarcia/2/iOS/Procore/Core/Utils/ObjectImportHelper+Relationships.swift:163


这是一些核心数据日志记录:
CoreData: sql: SELECT 0, t0.Z_PK FROM Z_55INSPECTION t1 JOIN ZGENERICATTACHMENT t0 ON t0.Z_PK = t1.Z_55ATTACHMENTS5 WHERE t1.Z_70INSPECTION = ? 
2019-01-25 13:50:17.727987-0800 Procore[34877:10124838] [logging] no such column: t1.Z_55ATTACHMENTS5
CoreData: annotation: Disconnecting from sqlite database due to an error.
2019-01-25 13:50:17.748021-0800 Procore[34877:10124838] [error] error: (1) I/O error for database at /var/mobile/Containers/Data/Application/FFEB392B-302B-479E-98E8-008333FC2714/Library/Application Support/Procore/Procore. SQLite error code:1, 'no such column: t1.Z_55ATTACHMENTS5'
CoreData: error: (1) I/O error for database at /var/mobile/Containers/Data/Application/FFEB392B-302B-479E-98E8-008333FC2714/Library/Application Support/Procore/Procore. SQLite error code:1, 'no such column: t1.Z_55ATTACHMENTS5'
CoreData: annotation: total fetch execution time: 0.0207s for 0 rows.
2019-01-25 13:50:17.748727-0800 Procore[34877:10124838] [error] error: exception during newFetchedPKsForSourceID: I/O error for database at /var/mobile/Containers/Data/Application/FFEB392B-302B-479E-98E8-008333FC2714/Library/Application Support/Procore/Procore. SQLite error code:1, 'no such column: t1.Z_55ATTACHMENTS5' with userInfo of {
NSFilePath = "/var/mobile/Containers/Data/Application/FFEB392B-302B-479E-98E8-008333FC2714/Library/Application Support/Procore/Procore";
NSSQLiteErrorDomain = 1;
}

我们正在使用 NSPersistentStoreDescription 的 shouldMigrateStoreAutomatically 和 shouldInferMappingModelAutomatically,我在日志中没有看到任何迁移错误(我们使用的是 -com.apple.CoreData.MigrationDebug 1)。

我们打开 SQLite 数据库文件,发现在迁移到这个新版本之前和之后,Z_55INSPECTION 表都有一个名为 Z_55ATTACHMENTS6(不是 Z_55ATTACHMENTS5)的列,我们将 localFilePath 属性添加到了 GenericAttachment。

那么为什么 Core Data 寻找名为 Z_55ATTACHMENTS5 而不是 Z_55ATTACHMENTS6 的列呢?

我们在谷歌搜索后发现了这两篇 Apple 邮件列表文章: a questionthis follow-up我认为这是说当多个实体与另一个实体具有相同名称的多对多关系时,列名末尾的数字会出现。在我们的例子中,我们有几个多对多的关系,称为 GenericAttachment 的附件。但是我们并没有添加一个叫做attachments的新关系,我们只是给GenericAttachment添加了一个属性。也许如果我们将所有这些关系重命名为唯一的,问题就会消失?

最佳答案

它选择该列,因为查询引用了 Z_55INSPECTION.Z_55ATTACHMENTS5 :

SELECT 0, t0.Z_PK FROM Z_55INSPECTION t1

JOIN ZGENERICATTACHMENT t0 ON t0.Z_PK = t1.Z_55ATTACHMENTS5

WHERE t1.Z_70INSPECTION = ?

最简单的方法可能是从 Z_55ATTACHMENTS6 重命名该列至 Z_55ATTACHMENTS5
...保留数据库的备份,以确保没有其他内容涉及它。

关于core-data - 核心数据异常 : SQLite "no such column" error after adding a new attribute to an entity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54383006/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com