Adding a column while upgrading throws "NoSuchMethodError : writeColumnDefinition " #2885
-
Hi I am trying to add a new column to the existing table and added a new table in my schema version 2. In the android emulator it worked fine for me. But When we deployed the same in IOS mobile, app throws error while opening that "NoSuchMethodError : The method 'writeColumnDefinition' is called on null". Below is my code. Please note I didnt used this columns in my app. I just wanted to test how my app will behave when a new table and column added. @override
MigrationStrategy get migration {
return MigrationStrategy(
onCreate: (Migrator m) async {
await m.createAll();
},
onUpgrade: (Migrator m, int from, int to) async {
if (from < 2) {
await m.createTable($InspectionDataBackUpTable(attachedDatabase));
await m.addColumn($InspectionDataListTable(attachedDatabase),
$InspectionDataListTable(attachedDatabase)._history);
}
},
);
} //----------------------------USERS------------------------------------------- |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Why are you re-creating the tables in the migration? You can access the tables in the database, so you can probably use if (from < 2) {
await m.createTable(inspectionDataBackUp);
await m.addColumn(inspectionDataBackUp, inspectionDataBackUp.history);
} At the very least, you should use the public column ( Or was the the point of a back up table to keep an earlier table definition? In that case, let drift generate step-by-step migrations for you instead. But I suppose you're on an older drift version if you're not using null safety, I'm not sure if the first version with support for those migration tools support your Dart version. |
Beta Was this translation helpful? Give feedback.
Hi I am not re creating any tables. I adding new table and adding an column to an existing table. Two different process. Anyhow issue got resolved when used public column "history". Thank you for your help.