We are testing our app and only one sqlite version. Because we don't want to upgrade the db before go live. During testing, we release few stable version to production whether google will accept or reject. Google accepted and now we realised that more than 1000 app downloaded.
But our testing is not done yet and we asked the user to manually uninstall. Now we don't know which version they start downloaded.
So without uninstall the app, their db is not latest and will error occurred.
So this coming release, we want to force delete their database and create latest db schemes. For subsequence release, if we need to change we will create new version of database with onUpdate.
Is there any better way to do so?
I think this code will help you
void _createTableCompanyV2(Batch batch) {
batch.execute('DROP TABLE IF EXISTS Company');
batch.execute('''CREATE TABLE Company (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
description TEXT
)''');
}
reference link
Related
I have a Flutter app and I am using Hive to store data.
I have deleted some adapters which were used previously. This caused an error and I have to delete the old database.
Now, if I roll out an update, how do I make sure the old Hive database gets deleted when the user updates the app so that it causes no issues.
Instead of deleting, run a database migration.
Hive.box("myBox", version: 5, migrator: (oldVersion, newVersion, box) async {
await box.delete("unusedKey");
await box.put("newKey", 7);
});
If you want to delete it anyway,
Read the app version, package_info may come in handy for that.
Delete the old db if this app version/build is running for the first time after installing/updating.
You can use box.clear() indeed this is an answer you may be expecting my Best Friend.
Hive.deleteFromDisk() can just wipe it clean.
I'm creating on my own a to-do app using Flutter. When I compile and try to insert a data in sqlite database, I got this error Flutter Sqlite Exception,No such table task, SQL logic Error.
Note: I use moor_ffi, moor
,and generate the database.g.dart file using command flutter packages pub run build_runner build.
From moor documentation:
Why am I getting no such table errors?
If you add another table after your app has already been installed,
you need to write a migration that covers creating that table. If
you’re in the process of developing your app and want to use un- and
reinstall your app instead of writing migrations, that’s fine too.
Please note that your apps data might be backed up on Android, so
manually deleting your app’s data instead of a reinstall is necessary
on some devices.
So everytime you have modified your database, you need to re-install your app or increase the schema version in your database.
#override
int get schemaVersion => 2;
I have a project and I am using core data.
I have some entities, with attributes. When I started the project I choose some atributes and now I want to change their types (Int to String for example). ANd so I did it.
THe thing is, I am getting errors...
I checked the code, I think every thing is ok.
I even deleted the entire entity and made a new one with some name but it doesn't work.
How can I change it with success?
You can use code data migration for this by creating new version..
To change data types you need to create a new version of the database, you can not just simply modifie it because that way your users would have to delete and redownload your app every time you change something.
Here you can read how to do this.
The simulator or device you are running the app on still 'remembers' the old type and data. Simply hold down on the app and press the 'X' to delete it. When you press play in XCode it will reinstall the app with the new data types.
I have a database that has 7 tables and am calling them from my app simply using sqlite queries ...
am not new to this I made to apps work greatly even with encryption ..
am building now a new app and decide to add 2 new tables my db ,
but when I call them sqlites doesnot see them and return me with an error "No such table :history"
I have added these new tables simply using sqlitemanger add-on that comes with firefox as I always do.
In the terminal I can see them and I can get data from them , but that is not the case in my app..
do you have any idea?!!
Try to delete your app from simulator and run it again.I think your updated database is not copied.
I am bit concern about the local database I have used in my application.
I want to maintain the data enter by user in the first version of application in second version also.
So i did one exercise in which I installed app with version 1.0 and enter few entry in my database from app. Then I installed app again with the version 2.0 and the data enter in the first version app are there in the second version also. Does that mean i don't have to do anything in order to keep users first version data in second version app.
Do let me know if any one has any idea.
Thanks in advance.
Yes, the user data (including databases) will stay around after application upgrades.
When you uninstall an application, its data will also be removed.
Does that mean i don't have to do anything in order to keep users first version data in second version app.
If you have changed the database schema for the new version, you will need to provide ways to continue to be able to read the old data or convert it to the new format. Otherwise, yes, it should just work.