Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] android – Room database error : IllegalStateException on Migration

Posted on November 14, 2022

Solution 1 :

As @BobSnyder said I’ve solved it by dropping the table first and the recreating the table. And it worked like a charm. So I’m putting his comment as answer in case anyone needs it in the future.

Problem :

I use Room persistence library for my database application. I’ve written a migration strategy to add a new table to existing database. I’m facing the following error.

Error:

java.lang.IllegalStateException: Migration didn't properly handle: table_audio_book(com.ridmik.app.audio_book.model.AudioBookInDb).
     Expected:
    TableInfo{name='table_audio_book', columns={book_path=Column{name='book_path', type='TEXT', affinity='2', notNull=true, primaryKeyPosition=0, defaultValue='null'}, stream=Column{name='stream', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, user_id=Column{name='user_id', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, audio_book_data=Column{name='audio_book_data', type='TEXT', affinity='2', notNull=true, primaryKeyPosition=0, defaultValue='null'}, audio_book_id=Column{name='audio_book_id', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, audio_book_name=Column{name='audio_book_name', type='TEXT', affinity='2', notNull=true, primaryKeyPosition=0, defaultValue='null'}, stream_path=Column{name='stream_path', type='TEXT', affinity='2', notNull=true, primaryKeyPosition=0, defaultValue='null'}, table_audio_book_row_id=Column{name='table_audio_book_row_id', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=1, defaultValue='null'}, last_closing_time=Column{name='last_closing_time', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}}, foreignKeys=[], indices=[]}

     Found:
    TableInfo{name='table_audio_book', columns={user_id=Column{name='user_id', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, audio_book_chapter_name=Column{name='audio_book_chapter_name', type='TEXT', affinity='2', notNull=true, primaryKeyPosition=0, defaultValue='null'}, audio_book_data=Column{name='audio_book_data', type='TEXT', affinity='2', notNull=true, primaryKeyPosition=0, defaultValue='null'}, audio_book_id=Column{name='audio_book_id', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, audio_book_name=Column{name='audio_book_name', type='TEXT', affinity='2', notNull=true, primaryKeyPosition=0, defaultValue='null'}, row_id=Column{name='row_id', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=1, defaultValue='null'}, last_closing_time=Column{name='last_closing_time', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}}, foreignKeys=[], indices=[]}

My Model Class:

@Entity(tableName = "table_audio_book")
data class AudioBookInDb (
        @PrimaryKey(autoGenerate = true)
        @ColumnInfo(name = "table_audio_book_row_id")
        val rowId: Long,

        @ColumnInfo(name = "audio_book_id")
        val bookId: Int,

        @ColumnInfo(name = "audio_book_name")
        val bookName: String,

        @ColumnInfo(name = "stream_path")
        val streamPath: String,

        @ColumnInfo(name = "book_path")
        val bookPath: String,

        @ColumnInfo(name = "stream")
        val stream: Boolean,

        @ColumnInfo(name = "audio_book_data")
        val audioBookData: String,

        @ColumnInfo(name = "user_id")
        val userId: Int,

        @ColumnInfo(name = "last_closing_time")
        val lastClosingTime: Long
)

My Migration Snippet:

public static final Migration MIGRATION_6_7 = new Migration(6, 7) {
    @Override
    public void migrate(SupportSQLiteDatabase database) {
        String createTableAudioBook = "CREATE TABLE IF NOT EXISTS `table_audio_book` (`table_audio_book_row_id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL," +
                " `audio_book_id` INTEGER NOT NULL, `audio_book_name` TEXT, `book_path` TEXT, `stream_path` TEXT, `stream` INTEGER NOT NULL, `audio_book_data` TEXT," +
                " `user_id` INTEGER NOT NULL, `last_closing_time` INTEGER NOT NULL)";
        database.execSQL(createTableAudioBook);

        Timber.d("Upgrading Database from version 6 to 7");
    }
};

Can anyone put me in right direction on how to solve this?

Comments

Comment posted by Bob Snyder

The “found table info” in the error message includes columns that do no exist in your migration statement to create the table, for example:

READ  [ANSWERED] How to put an android layout's element over another one
Powered by Inline Related Posts

Comment posted by miq0717

@BobSnyder Thanks man. Worked like a charm! The problem was I when I created the table I used

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress