Note that there are some explanatory texts on larger screens.

plurals
  1. POCore Data Lightweight Migration failure - "table ZTABLENAME already exists"
    primarykey
    data
    text
    <p>NB! I have seen <a href="https://stackoverflow.com/questions/9897452/core-data-migration-table-already-exists">Core Data Migration - Table Already Exists</a>, and it did not solve my problem.</p> <p>I'm trying to do a lightweight migration of my data model, and am getting a failure at this point:</p> <pre><code>NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil]; store = [self addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:url options:options error:&amp;error]; </code></pre> <p>The error message is:</p> <pre><code>2012-09-06 17:14:19.450 Selene[79064:c07] CoreData: error: (1) I/O error for database at /Users/colin/Library/Application Support/iPhone Simulator/5.1/Applications/E1638F38-B13A-4728-91CD-CC380E761544/Library/Application Support/Selene/.Selene.sqlite.migrationdestination_41b5a6b5c6e848c462a8480cd24caef3. SQLite error code:1, 'table ZMEASUREMENT already exists' </code></pre> <p>The actual change to the data model is the addition of a single optional string column on a completely different table, ZCYCLE. So it makes no sense that it's complaining about ZMEASUREMENT.</p> <p>I've stepped through the core data instantiation, and the NSManagedObjectModel looks like it is loaded correctly (new version). The url is correct.</p> <p>I've tried making Clean in xcode, Reset Contents and Settings... in iOS Simulator, regenerate a version-1 sqlite file from scratch (using Core Data), and then try migration to version-2 again -- no dice. So it's not that my sqlite file is corrupt somehow.</p> <p>Is data model information stored anywhere else that my cleaning might have missed?</p> <p>Is there any other way to debug what's actually happening in the lightweight migration? I can't find any information other than the "table already exists" error quoted above, which doesn't make any sense to me. Whatever's going on inside addPersistentStoreWithType: is opaque to me.</p> <p>The only way I have found to get a migration to proceed is to rename the table Core Data is complaining about, ZMEASUREMENT, as part of the migration. This works for one(1) migration only, and then I have to rename the table again to do a second migration. I am really not ok with the idea of a table whose name has to change every time I alter my data model; surely Core Data is not this broken.</p> <p>EDIT: In case it helps, here's the list of attributes for table ZMEASUREMENT. Is any of this weird?</p> <pre><code>@property (nonatomic) int epochDay; // Integer32 indexed // time as number of seconds since local midnight, to avoid time zone and DST issues @property (nonatomic, strong) NSNumber *localTime; // Integer32 optional // stored in Kelvins, to force me to test temperature conversion code properly @property (nonatomic, strong) NSNumber *temperatureK; // Float optional @property (nonatomic) BOOL excludeTemperature; // Boolean default=NO @property (nonatomic, strong) NSNumber *fluidCode; // Integer16 optional @property (nonatomic, strong) NSNumber *openingCode; // Integer16 optional @property (nonatomic, strong) NSNumber *positionCode; // Integer16 optional @property (nonatomic, strong) NSNumber *textureCode; // Integer16 optional @property (nonatomic, strong) NSNumber *rateCode; // Integer16 optional @property (nonatomic, strong) NSNumber *heightCode; // Integer16 optional // try renaming the internal property to see if it helps lightweight migration @property (nonatomic, strong) NSString *commentDPL; // String optional @property (nonatomic, strong) NSString *comment; /* derived property (alias for commentDPL) */ @property (nonatomic, strong) NSSet *notes; // Optional to-many relationship to MeasurementNote </code></pre> <p>The only non-optional fields are epochDay and excludeTemperature.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload