go-pg / pg

Golang ORM with focus on PostgreSQL features and performance
https://pg.uptrace.dev/
BSD 2-Clause "Simplified" License
5.67k stars 404 forks source link

CreateTable method not accepting CreateTableOptions struct #1935

Closed darienmiller88 closed 2 years ago

darienmiller88 commented 2 years ago

I just tried using using the migration method as stated in the example -> db.Model(&User{}).CreateTable(&orm.CreateTableOptions{})

But unfortunately, I'm getting this error:

"cannot use &"github.com/go-pg/pg/orm".CreateTableOptions{} (type "github.com/go-pg/pg/orm".CreateTableOptions) as type "github.com/go-pg/pg/v10/orm".CreateTableOptions in argument to p.NewDB.baseDB.Model(&gorm.Model{}).CreateTable"

This doesn't make sense to me, as the .CreateTable() method clearly takes a reference to a CreateTableOptions{}struct looking at the documentation.

Expected Behavior

For the method to accept the above argument, a CreateTableOptions{}struct.

Current Behavior

The above error is being displayed.

Steps to Reproduce

func main(){
     db := pg.Connect(&pg.Options{
                User: "",
        Password: "",
        Database: "",
    })

     db.Model(&models.User{}).CreateTable(&orm.CreateTableOptions{}) //<- This is causing the error, why won't the method accept this struct?

}
elliotcourant commented 2 years ago

"github.com/go-pg/pg/orm".CreateTableOptions{} looks like its being imported from the non-module version.

go-pg expects you to use the module version *"github.com/go-pg/pg/v10/orm".CreateTableOptions

I think your imports are incorrect, or you are not using go modules.

darienmiller88 commented 2 years ago

These are my imports:

"github.com/go-pg/pg/orm"
"github.com/go-pg/pg/v10"

I'm pretty sure these are correct right?

elliotcourant commented 2 years ago

I think you want github.com/go-pg/pg/v10/orm instead of github.com/go-pg/pg/orm

darienmiller88 commented 2 years ago

Awesome, that was the issue! Thank you, closing this.