[SOLVED] Ionic 2 => 3 problem with database (Ionic Native Storage)

Hi there.
This week, I did de upgrade of Ionic 2 to Ionic 3. Everything is working perfectly after making the necessary conversions and import changes, but, I’m experiencing a problem that I can not resolve despite trying many times:

After I update my App (now with Ionic 3) on my device I already had the app (with Ionic 2), the plugin Ionic Native Storage can’t get storage data in devices who have the old version (Ionic 2).

In my App (with Ionic 2), I have this code:

In app.module.ts, I had:

  imports: [

In my class (with Ionic 2) I have this code:

    constructor(public http: Http) {
        this.storage = new Storage();

In Ionic 2, that code works perfectly. But, AFTER I update to Ionic 3, the class Storage requires arguments on your call, for example:

    constructor(public http: Http) {
        this.storage = new Storage({
            name: 'my_database'

This code run perfectly, BUT, If a user have my App Old Version (with Ionic 2) and this user updates the application to the new App Version (Ionic 3), the USER STORAGE DATA IS LOST. I believe it’s because the name of database in Ionic 2 is different of the database name in Ionic 3.

Finally, my question: What should I do so that the Storage class can view the stored data?


Does the new version really require a manual set name?
Try to find out the name that was set before automatically.

Shouldn’t Storage be handled by DI (Dependency Injection) rather than manual creation?

1 Like

In Ionic 3, If I use new Storage() without params inside in ( ), One error is show describe who Storage() need One param.

I’ve tried tô discovery the name of database. The name who I found is ‘_ionicstorage’. But, If I pass this name with params, the data is lost.

In tutorial who I follow 6 months ago, show to use this form.

Bad tutorial :confused:

Official usage example also shows DI: https://ionicframework.com/docs/storage/#usage

Thanks for your reply! :smiley:

From what I understand in the documentation, I do not need to specify the name of the database. It was this idea I followed from the tutorial. What I do not understand is because before I could do this:

constructor(public http: Http) {
    this.storage = new Storage();

And now, I need this:

constructor(public http: Http) {
    this.storage = new Storage({
        name: 'my_database'

This is my “problem”

That’s the relevant part:

export class MyApp {
  constructor(private storage: Storage) { }

Thanks for reply.
After tried many times, I just remove plugin and readded.

After readded the plugin, it’s works.

But, I have one question:

In the docs (https://ionicframework.com/docs/storage), we have the following text:

The Storage engine can be configured both with specific storage engine priorities, or custom configuration options to pass to localForage.

Based in the text above, I understand that specifying the bank name in NgModule is totally optional.
Do not specify the name of the bank really is good practice?

Thanks again!

They’ve set reasonable defaults, or at least ones that most people will want, so yes it’s good practice.

1 Like

Hum… Nice! :smiley:

Thanks all!