Migration AlterTable Add new column not work?
See original GitHub issueHi @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:
- 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;
}
- 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:
- Created 8 years ago
- Comments:5
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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:
The reason: I was passing an unassigned String to addColumn. Imagine this:
I know it’s a dumb issue, but I wasted several hours finding it. Maybe it helps someone else.
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;