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.

Migration AlterTable Add new column not work?

See original GitHub issue

Hi @graiz , I have a table

@Table(databaseName = MyDatabase.NAME)
@ModelContainer
public class Lead extends BaseModel {

    @Column
    @PrimaryKey
    @Expose
    String objectId;

    @Column
    @Expose
    String name;
}

Now I want to add new column into this table, I do following step:

  1. Add new column into Lead.class
@Table(databaseName = MyDatabase.NAME)
@ModelContainer
public class Lead extends BaseModel {

    @Column
    @PrimaryKey
    @Expose
    String objectId;

    @Column
    @Expose
    String name;

    @Column
    @Expose
    String otherInfos;
}
  1. Create Migration:
@Migration(version = 4, databaseName = MyDatabase.NAME)
public class Migration1 extends AlterTableMigration<Lead> {

    public Migration1() {
        super(Lead.class);
    }

    public Migration1(Class<Lead> table) {
        super(table);
    }

    @Override
    public void onPreMigrate() {
        super.onPreMigrate();
        addColumn(String,class, Lead$Table.OTHERINFOS);
    }
}

but It returns error:

android.database.sqlite.SQLiteException: no such column: otherInfos (code 1):

Can you help me to solve this?

Thanks a lot!!

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
voghDevcommented, Jan 19, 2016

I was having a stupid mistake that made me waste hours. I just want you guys to know, to avoid someone from doing the same. The error I was getting is:

Process: com.company.app.flavor, PID: 6381
java.lang.RuntimeException: java.lang.NullPointerException
at com.raizlabs.android.dbflow.runtime.DBTransactionQueue.run(DBTransactionQueue.java:75)
Caused by: java.lang.NullPointerException

The reason: I was passing an unassigned String to addColumn. Imagine this:

public static final String STR;

@Override
public void onPreMigrate() {
    super.onPreMigrate();

    addColumn(String.class, STR);
}

I know it’s a dumb issue, but I wasted several hours finding it. Maybe it helps someone else.

0reactions
narimetisaigopicommented, Feb 23, 2017

remove

public Migration1() { super(Lead.class); } one constructor is enough if not it gives an error

incremnet your database version number and use version = Mydatabase.VERSION;

Read more comments on GitHub >

github_iconTop Results From Across the Web

Laravel Add a new column to existing table in a migration
To create a migration, you may use the migrate:make command on the Artisan CLI. Use a specific name to avoid clashing with existing...
Read more >
How to Add a New Column to an Existing Table in a Laravel ...
In this tutorial, you will learn how to add a new column to an existing table in a Laravel Migration! Prerequisites. Before you...
Read more >
How to add a new column to existing table of laravel ... - Edureka
Your answer ; To create a migration, you may use the migrate:make command on the Artisan CLI. Use a specific name to avoid...
Read more >
How to add a new column to an existing table of Laravel in a ...
So add the address column to be dropped inside the down() method. This is useful if the migration command is executed again.
Read more >
Database: Migrations - The PHP Framework For Web Artisans
A migration class contains two methods: up and down . The up method is used to add new tables, columns, or indexes to...
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