Skip to content

Error duplicate column name: Id when migrate DB #576

@nguyenconghoan

Description

@nguyenconghoan

I want add new table Products into current DB.

I have performed the following steps:
Step 1: Change files AndroidManifest.xml

<meta-data
    android:name="AA_DB_VERSION"
    android:value="2" />

Step 2: Create new file 2.sql in folder assets/migrations

DROP TABLE IF EXISTS "Products";
CREATE TABLE IF NOT EXISTS "Products" ("Id" INTEGER,"p_name" TEXT,"p_des" TEXT,"p_price" TEXT);

Step 3: Create new file Products.java

@Table(name = "Products")
public class Products extends Model implements Serializable {
    @Column(name = "Id")
    public Integer Id;
    @Column(name = "p_name")
    public String p_name;
    @Column(name = "p_des")
    public String p_des;
    @Column(name = "p_price")
    public String p_price;

    public Products() {
        super();
    }

}

When I update the version app, I get the following error:
SQLiteLog: (1) duplicate column name: Id in "CREATE TABLE IF NOT EXISTS Products (Id INTEGER PRIMARY KEY AUTOINCREMENT, Id INTEGER PRIMARY KEY AUTOINCREMENT, p_name TEXT, p_des TEXT, p_price TEXT);"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions