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: unable to initialize tables #421

Closed tiger5226 closed 5 years ago

tiger5226 commented 5 years ago

gen_models.sh

#!/bin/bash

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$DIR"
cd ".."
DIR="$PWD"
(
  cd "$DIR"
  go get -u -t github.com/volatiletech/sqlboiler
  sqlboiler --no-auto-timestamps --no-hooks --no-tests --no-context --wipe mysql
)

Error

MacBook-Pro:chainquery Mark$ ./scripts/gen_models.sh
Error: unable to initialize tables: unable to fetch table data: something totally unexpected happened when running the binary driver /Users/Mark/go/src/github.com/lbryio/chainquery/sqlboiler-mysql: fork/exec /Users/Mark/go/src/github.com/lbryio/chainquery/sqlboiler-mysql: no such file or directory

This is an odd one. It's looking for a binary driver in the wrong location.

So I created the folder to see if I can get around this problem.

Error: unable to initialize tables: unable to fetch table data: something totally unexpected happened when running the binary driver /Users/Mark/go/src/github.com/lbryio/chainquery/sqlboiler-mysql: fork/exec /Users/Mark/go/src/github.com/lbryio/chainquery/sqlboiler-mysql: permission denied

I got a different error, but I also chmod 777 just in case and I get the same error. So I am stuck. The last time I generated for the model was at the end of August. Not sure what changed.

So I did some research, realized V3 is now the main thing to use. Amazing video!! So I ran the go get for the driver.

go get -u -t github.com/volatiletech/sqlboiler/drivers/sqlboiler-mysql

MacBook-Pro:chainquery Mark$ ./scripts/gen_models.sh
unable to get table names: x509: certificate is valid for MySQL_Server_5.7.21_Auto_Generated_Server_Certificate, not localhost
Error: unable to initialize tables: unable to fetch table data: driver (/Users/Mark/go/bin/sqlboiler-mysql) exited non-zero: exit status 1
tiger5226 commented 5 years ago

For now I was able to work around this issue, by building a local version of sqlboiler from the 2.7.4 tag, placing it in the go path, and running it as normal.

Interesting enough I could not even use go get -u -t gopkg.in/volatiletech/sqlboiler.v2

aarondl commented 5 years ago

Note that gopkg.in is a deprecated way of using sqlboiler. And you should be cloning (and vendoring) using tools like dep, glide but probably go modules is the best way.

I can't really understand what's going on there, seems like it may be a problem with your mysql ssl configuration? Have you tried disabling it in the config?

tiger5226 commented 5 years ago

Yeah, its disabled in the config. It is a weird one. I was just trying to use gopkg.in to make sure I get v2 because I could not sucessfully upgrade to v3 at the time. I still have not put additional effort yet, but I will have to. For the cert issue, I did not make any changes, so I figured maybe you had seen or heard of this from others upgrading. The web is very generic. When I find the root cause of this from the v3 upgrade, I will post it here for others. I presume that are some additional assumptions added/removed that trigger this error. Just need to figure out where.

tiger5226 commented 5 years ago

I still have not resolved this problem and am stuck with V2 right now. Going to try and put some time in today digging into the application. Something definitely changed in V3 that this is now a problem.

tiger5226 commented 5 years ago

Ok the problem was the toml. sslmode=false does not work for V3. sslmode="false" does.

All the null checks are missing now though. So I can't do MyTable.MyColumn.IsNull() anymore. Trying to find out of there is some backwards compatibility added in for this. Did not see it mentioned in the V3 video. I saw mentions of type replacements...maybe that has something to do with this. It would be alot easier to upgrade if the null library could be retained I guess.

tiger5226 commented 5 years ago

going to close this as I am now upgraded to v3.

aarondl commented 5 years ago

@tiger5226 curious what you mean by the IsNull thing doesn't exist anymore. We haven't changed the null package almost at all. It's possible your column type got changed but there was no intentional breakage with what you're talking about in this issue about null stuff.

tiger5226 commented 5 years ago

So it appears that the null package uses IsZero() now instead of IsNull(). I confirmed again just to be sure and it is definitely null.String type. And the package its using in the generated code is "github.com/volatiletech/null". Do you think something is wrong? I did not merge the upgrade yet but I have tested ( not the IsZero specifically ) generally and things appear ok.

aarondl commented 5 years ago

It just seems weird since nothing should have changed in this area.

mehdiym commented 5 years ago

Hello, I had a similar issue: Error: unable to initialize tables: unable to fetch table data: something totally unexpected happened when running the binary driver /home/myo/go/src/project/sqlboiler-mysql: fork/exec /home/myo/go/src/project/sqlboiler-mysql: no such file or directory After some debugging, I found out that in my .bashrc, I set the $PATH with a ~/go/bin and Exec.LookPath() doesn't seem to work with ~. After replacing that path with a full path it works.

juricake commented 7 months ago

Hey, I had the same issue with sqlboiler v3.7.1.

I was able to resolve mine with the following steps:

  1. rm $(which sqlboiler)
  2. rm $(which sqlboiler-mysql)
  3. go get -u -t github.com/volatiletech/sqlboiler
  4. go get -u -t github.com/volatiletech/sqlboiler/drivers/sqlboiler-mysql
  5. export PATH=$PATH:$GOPATH/bin # or export PATH=$PATH:$HOME/go/bin