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

sqlite3 migration fails: duplicate column name: id #865

Closed
ArmstrongCN opened this issue Feb 24, 2016 · 2 comments
Closed

sqlite3 migration fails: duplicate column name: id #865

ArmstrongCN opened this issue Feb 24, 2016 · 2 comments

Comments

@ArmstrongCN
Copy link

Error:

duplicate column name: id

Log:

SELECT count(*) FROM sqlite_master WHERE tbl_name = 'users' AND (sql LIKE '%!((MISSING)"id" %!'(MISSING) OR sql LIKE '%!,(MISSING)"id" %!'(MISSING) OR sql LIKE '%!,(MISSING) "id" %!'(MISSING) OR sql LIKE '%!((MISSING) id %!'(MISSING) OR sql LIKE '%!,(MISSING) id %!'(MISSING) OR sql LIKE '%!,(MISSING)id %!'(MISSING));
ALTER TABLE "users" ADD "id" varchar(64) NOT NULL UNIQUE;

the struct:

type User struct{
    Id  string `gorm:"primary_key";sql:"not null;unique;size:64"`
    Username string `sql:"not null;unique;size:32"`
    Email string `sql:"not null;unique;size:64"`
    Password string `sql:"not null;size:64"`
    CreatedAt time.Time 
    UpdatedAt time.Time
}

sqlite describe table:

CREATE TABLE users (
    "id" VARCHAR(255),
    "username" VARCHAR(255) NOT NULL,
    "password" VARCHAR(64) NOT NULL,
    "created_at" DATETIME,
    "updated_at" DATETIME
, "email" TEXT)

what does the "MISSING" in logs means? is that the finnal sql statement executed?

@jinzhu
Copy link
Member

jinzhu commented Mar 4, 2016

Hello @ArmstrongCN

Could you upload your sqlite db here for teting, I think the check HasColumn sql get some thing wrong with your data.

@ArmstrongCN
Copy link
Author

here is my db file. i wipe the data but the error still can be reproduced.
db.zip

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