volatiletech / sqlboiler

Generate a Go ORM tailored to your database schema.
BSD 3-Clause "New" or "Revised" License
6.73k stars 544 forks source link

Error: (random.go) assignment mismatch: 2 variables but 1 values #355

Closed gencer closed 6 years ago

gencer commented 6 years ago

What version of SQLBoiler are you using (sqlboiler --version)?

v3.0.0-rc9

If this happened at runtime what code produced the issue?

Tried:

sqlboiler psql --add-global-variants --no-context and sqlboiler psql both generates models but go build / go run fails in any way

    db, err = sql.Open("postgres", "...")
    defer db.Close()

    if err != nil {
        fmt.Println(err)
    }
    boil.SetDB(db)
    m, _ = models.FindMessage(db, 1) // or just 1 or ctx, 1.....
    // do with :m

Schema (psql), Model and main() is attached here: https://gist.github.com/gencer/31d3a41f639ed34504036faa28c75b81

What I get?

# ...vendor/github.com/volatiletech/sqlboiler/randomize
vendor\github.com\volatiletech\sqlboiler\randomize\random.go:46:19: assignment mismatch: 2 variables but 1 values

Further information. What did you do, what did you expect?

v2 is just works. I upgraded to v3 and can't go one step further.

aarondl commented 6 years ago

Your problem is here: https://github.com/volatiletech/sqlboiler/blob/v3.0.0-rc9/randomize/random.go#L46

The issue is that satori.uuid made a breaking change to their API and you still have the older version of satori.uuid - in order to fix this problem upgrade your satori.uuid dependency. In the latest in the v3 branch (not tagged, but perfectly usable) we've actually removed the satori.uuid library for a properly maintained fork because of problems like this: https://github.com/satori/go.uuid/issues/73 so another fix for you could be just using the latest v3 branch.

gencer commented 6 years ago

@aarondl thanks for the prompt answer. v3 branch fixed my issue.

BTW, If you take above sample (gist) I have one more issue. No matter what I do Message table inserts ID as 0. It does not increment value. Always 0. You can see model and schema in gist.

What I do is:

    var p1 models.Message
    uid := null.Int64{Int64: 1, Valid: true}
    p1.UserID = uid
    err := p1.Insert(db, boil.Infer())

Error: models: unable to insert into messages: pq: duplicate key value violates unique constraint "messages_pkey"

gencer commented 6 years ago

I think I've found the problem. PostgreSQL introduced GENERATE IDENTITY feature in 10.2 to drop-in replacement for SERIAL. When a table id generated using an IDENTITY it does not have a default value like SERIAL has (which is: nextval('test_id_seq'::regclass) ).

Due to this, ID is always 0.

See #356