Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error duplicate column name: Id when migrate DB #576

Open
nguyenconghoan opened this issue May 19, 2022 · 1 comment
Open

Error duplicate column name: Id when migrate DB #576

nguyenconghoan opened this issue May 19, 2022 · 1 comment

Comments

@nguyenconghoan
Copy link

nguyenconghoan commented May 19, 2022

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);"

@azizimusa
Copy link

  1. Don't need to add column "Id". AA will auto add it.
  2. You don't need to assign column (@column(name = "p_price") if the name is same as variable. Just make it "@column" is enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants