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.

AlterTableMigration to add column throws compile-time error

See original GitHub issue

DBFlow Version: 4.0.4 Issue Kind (Bug, Question, Feature): Question

Description: I have a table that I want to add a column to. I added the column in the Model class and added the below class to my Database class.

`@Migration(version = WizardryDatabase.VERSION, priority = 0, database = WizardryDatabase.class) public class Migration3 extends AlterTableMigration<Bibliography> {

    public Migration3(Class<Bibliography> table) {
        super(table);
    }

    @Override
    public void onPreMigrate() {
        super.onPreMigrate();
        addColumn(SQLiteType.TEXT, "test");
    }
}`

However, I am getting this error when compiling: Error:(18, 21) error: an enclosing instance that contains WizardryDatabase.Migration3 is required

I have incremented the version number in the Database class.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
agrosnercommented, Jul 11, 2017

make the inner class static. it appears you’re making it inner.

1reaction
AllanWangcommented, Jul 13, 2017

@strapp342

Thanks a lot. For those who were confused like me, here is my example with Kotlin:

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

@Migration(version = 2, database = NotificationDb::class)
class NotificationMigration2(modelClass: Class<NotificationModel>) : AlterTableMigration<NotificationModel>(modelClass) {
    override fun onPreMigrate() {
        super.onPreMigrate()
        addColumn(SQLiteType.INTEGER, "epochIm")
        L.d("Added column")
    }
}

@Table(database = NotificationDb::class, allFields = true, primaryKeyConflict = ConflictAction.REPLACE)
data class NotificationModel(@PrimaryKey var id: Long = -1L, var epoch: Long = -1L, var epochIm: Long = -1) : BaseModel()

where NotificationModel didn’t have epochIm in version 1.

Make sure to also change the versions, since that was my mistake for the past little while…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Confusion on Room Auto Migration with NOT NULL ...
Long Version. This code tell me that Room Compiler will throw an exception if new column is nonNull BUT it has not being...
Read more >
Framework support for implementing column alterations #240
The official SQLite docs recommend implementing the following process to achieve column alterations that they do not support:
Read more >
Fixing ALTER TABLE errors with Flask-Migrate and SQLite
A nasty type of issue occurs when the ALTER TABLE error occurs in the middle of a migration, after some operations were already...
Read more >
Migrating Room databases
If Room detects ambiguous schema changes and it is unable to generate a migration plan without more input, it throws a compile-time error...
Read more >
Database Engine events and errors - SQL Server
Consult this MSSQL error code list to find explanations for error messages for SQL Server database engine events.
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