question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

renameFrom in AlterTableMigration is giving an SQLiteException

See original GitHub issue

DBFlow Version: 4.1.2

Bug or Feature Request: renameFrom is causing exception in basic application.

Link for code before migration: Before Migration Link for code after migration: After Migration

Description:

Following error received when running renameFrom: android.database.sqlite.SQLiteException: there is already another table or index with this name: DiaryLogEntry (code 1): , while compiling: ALTER TABLE 'LogEntry' RENAME TO 'DiaryLogEntry'

Relevant code below or in the Github link provided Database Before Migration

@Database(name = MainDB.NAME, version = MainDB.VERSION)
object MainDB {
    const val NAME = "MainDB"
    const val VERSION = 1
}

Table Before Migration

@Table(database = MainDB::class, allFields = true)
class LogEntry {

    @PrimaryKey
    lateinit var entryId: String

    lateinit var entryTitle: String
}

Database After Migration

@Database(name = MainDB.NAME, version = MainDB.VERSION)
object MainDB {
    const val NAME = "MainDB"
    const val VERSION = 2
}

@Migration(version = MainDB.VERSION, database = MainDB::class)
internal class MainDBMigration1 : AlterTableMigration<DiaryLogEntry>((DiaryLogEntry::class.java)) {

    init {
        renameFrom("LogEntry")
        Timber.d("New name given to LogEntry. It is now DiaryLogEntry.")
    }
}

Table After Migration

@Table(database = MainDB::class, name = "DiaryLogEntry", allFields = true)
class DiaryLogEntry {

    @PrimaryKey
    lateinit var entryId: String

    lateinit var entryTitle: String
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
theaircrashercommented, Oct 25, 2018

Thanks, for your tip. I will try that.

0reactions
techwnncommented, Jan 14, 2019

Note it might have issues on new installs, so its not perfect.

I am using version 4.2.4(because I failed to include 5.0.1alpha),and I got the same problem. I think this is a issue which need to be fixed. now, we can do like this:

  1. create new table
  2. copy data from old to new
  3. delete old table
Read more comments on GitHub >

github_iconTop Results From Across the Web

Room Database Migration doesnt properly handle ALTER ...
The error message is hard to parse, but there's a difference: TableInfo{name='user', columns={name=Column{name='name', type='TEXT', ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found