Closed robinbonnes closed 4 years ago
Hi @robinbonnes and thank you for trying out sqflite_migration!
It would be great if you could provide the output of flutter doctor
and maybe a test case. It would greatly improve the time needed to debug and fix this.
If you have already spotted a possible fix feel free to create a PR 😃
I've also encountered this problem. I think the steps to reproduce are as follows - this is just what I have done. Sorry I don't have time to investigate furhter, I'm massively under pressure to code my ass off at the moment.
Thanks for the great plugin, definitely fulfulls an unmet need in flutter!
I've just implemented the logic manually as described in your article here. I got the same problem using this code:
onUpgrade: (Database db, int oldVersion, int newVersion) async {
for (var i = oldVersion - 1; i <= newVersion - 1; i++) {
await db.execute(migrationScripts[i]);
}
}
Is there a mistake - shouldn't it be while i < newVersion - 1
in the for loop? When I use that, it works.
@jamesncl can you try with the newest version of the library?
I have the same issue, I have an List
Hi @marcelovbcfilho there is an implicit assertion that in version 1 there are nomigrationScripts
but rather only initializationScript
. This means that the version of the database is always the number of migrationScripts
+ the initialization script. So config.migrationScripts.length + 1
holds this logic.
I have the same problem. It fails on this assert assert(config.migrationScripts.length >= newVersion, 'New version ($newVersion) requires ${newVersion - config.migrationScripts.length} migrations more than what you have.');
in executeMigration
.
Shouldn't that be config.migrationScripts.length >= newVersion - 1
since the version is config.migrationScripts.length + 1
?
I believe @jamesncl is right about the for loop condition as well.
Same problem! Any solution?
Correct will be like this in migrator.dart:
` Future
for (var i = oldVersion - 1; i < newVersion - 1; i++) {
await db.execute(config.migrationScripts[i]);
}
}`
con mi amigo Matias Araus lo resolvimos de la siguiente forma:
final migrationScripts = [
'CREATE TABLE Cuotas ('
' idcuota INTEGER PRIMARY KEY, '
' creditoid INTEGER, '
' descripcion TEXT, '
' importecuota REAL, '
' codigo INTEGER, '
' razonsocial TEXT, '
' direccion TEXT, '
' importepagado REAL, '
' localidad TEXT, '
' tipocuota TEXT '
')',
'update cuotas set importecuota = importecuota + 2 ',
'update cuotas set importecuota = importecuota + 3',
'update cuotas set importecuota = importecuota + 4',
'update cuotas set importecuota = importecuota + 5 ',
'update cuotas set importecuota = importecuota + 6 ',
];
initDB() async {
Directory documentDirectory = await getApplicationDocumentsDirectory();
final path = join(documentDirectory.path, 'database12.db');
return await openDatabase(path, version: migrationScripts.length ,
onCreate: (Database db, int version) async {
migrationScripts.forEach((script) async => await db.execute(script));
}, onUpgrade: (Database db, int oldVersion, int newVersion) async {
for (var i = oldVersion ; i < newVersion ; i++) {
await db.execute(migrationScripts[i]);
}
});
}
Con una sola lista, ya que el create solo ingresa por unica vez al crear el archivo, y esa primera vez el onUpgrade no se ejecuta porque oldversion no existe aun.
Same issue. For now I'm using dependency as:
git: https://github.com/DrLabx/sqflite_migration/
Thanks for that.
But as @marcelovbcfilho pointed out 9 months ago - this simply cannot work correctly ever. Please merge the pull request and release a new version.
Same issue. For now I'm using dependency as:
git: https://github.com/DrLabx/sqflite_migration/
Thanks for that.
But as @marcelovbcfilho pointed out 9 months ago - this simply cannot work correctly ever. Please merge the pull request and release a new version.
You're welcome! I've sent an email to the maintainer, but haven't had any response yet. Hopefully he'll come to us soon.
Sorry for leaving this hanging for so long ... I had some personal and professional issues to sort out. I will dig deeper into this issue and will get back ASAP.
Thanks for this great plugin.
However, when I migrate it says:
Failed assertion: line 27 pos 12: 'config.migrationScripts.length >= newVersion': New version (2) requires 1 migrations more than what you have.
Also it gives a non-fatal error when you start with an empty migration array.