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

AutoMigrate failed (type "bigserial" does not exist) #4792

Closed
enzofoucaud opened this issue Oct 19, 2021 · 17 comments
Closed

AutoMigrate failed (type "bigserial" does not exist) #4792

enzofoucaud opened this issue Oct 19, 2021 · 17 comments
Assignees
Labels
type:with reproduction steps with reproduction steps

Comments

@enzofoucaud
Copy link

enzofoucaud commented Oct 19, 2021

GORM Playground Link

go-gorm/playground#391

Existing database without using GORM :

DROP TABLE IF EXISTS "events";
DROP SEQUENCE IF EXISTS events_id_seq;
CREATE SEQUENCE events_id_seq INCREMENT 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1;
CREATE TABLE "public"."events" (
    "id" integer DEFAULT nextval('events_id_seq') NOT NULL,
    "town" text NOT NULL,
    "latitude" real NOT NULL,
    "longitude" real NOT NULL,
    "kind" text NOT NULL,
    "species" text NOT NULL,
    "description" text NOT NULL,
    "user_publisher" integer NOT NULL,
    "time" timestamp NOT NULL,
    "disabled" integer NOT NULL,
    "report" integer NOT NULL,
    CONSTRAINT "events_pkey" PRIMARY KEY ("id")
) WITH (oids = false);

Model used with GORM :

type Event struct {
	gorm.Model
	Town           string    `gorm:"not null"`
	Latitude       float64   `gorm:"not null"`
	Longitude      float64   `gorm:"not null"`
	Kind           string    `gorm:"not null"`
	Species        string    `gorm:"not null"`
	Description    string    `gorm:"not null"`
	User_Publisher int       `gorm:"not null"`
	Time           time.Time `gorm:"not null"`
	Disabled       int       `gorm:"not null"`
	Report         int       `gorm:"not null"`
}

Function that opens the database and migrates the data :

func (store PostgresRepository) Open(dsn string) (*PostgresRepository, error) {
	// Open database
	db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
	if err != nil {
		return nil, err
	}
	log.Info().Msg("Connected to db")

	// Create the new SQLite repository
	sql := NewPostgresRepository(db)

	// Migration database
	if err := db.AutoMigrate(&Event{}); err != nil {
		return nil, err
	}

	return sql, nil
}

Error : 2021/10/19 15:14:19 /home/enzo/go/pkg/mod/gorm.io/driver/postgres@v1.1.2/migrator.go:252 ERROR: type "bigserial" does not exist (SQLSTATE 42704)

Description

Before using GORM I was using pgxscan and doing automatic migrations via a script.
Recently I switched to GORM which is more efficient but I get this error during the migration.

Why do I get this error?

Same problem here #4765

@github-actions github-actions bot added the type:missing reproduction steps missing reproduction steps label Oct 19, 2021
@github-actions
Copy link

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 2 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.ioSearch Before Asking

@ghost
Copy link

ghost commented Oct 19, 2021

@enzofoucaud hello, can you provide a demo in https://github.com/go-gorm/playground?

@github-actions
Copy link

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 2 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.ioSearch Before Asking

@enzofoucaud
Copy link
Author

I try it when I have time

@github-actions
Copy link

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 2 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.ioSearch Before Asking

@enzofoucaud
Copy link
Author

@longlihale

go-gorm/playground#391

@github-actions
Copy link

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 2 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.ioSearch Before Asking

@github-actions github-actions bot added status:stale type:with reproduction steps with reproduction steps and removed type:missing reproduction steps missing reproduction steps status:stale labels Oct 21, 2021
@enzofoucaud
Copy link
Author

Hello, any news about this issue ?

@Hanggi
Copy link

Hanggi commented Nov 3, 2021

Any updates or work around? It seems to cause auto migration fail.

@ghost
Copy link

ghost commented Nov 4, 2021

I see see....:kissing_closed_eyes:

@ghost ghost self-assigned this Nov 4, 2021
@enzofoucaud
Copy link
Author

I see see....😚

Thanks, because I want to launch my app in prod :)

@mehdipourfar
Copy link

I'm also facing this problem after updating gorm

@enzofoucaud
Copy link
Author

enzofoucaud commented Nov 9, 2021

I'm also facing this problem after updating gorm

Which version ?

I tested v1.22.2 & v1.21.16

@mehdipourfar
Copy link

I'm also facing this problem after updating gorm

Which version ?

I tested v1.22.2 & v1.21.16

After this updates in dependencies:

  •   gorm.io/driver/postgres v1.1.0  ----> gorm.io/driver/postgres v1.2.1
    
  •   gorm.io/gorm v1.21.13 ----> gorm.io/gorm v1.22.2
    

@benjamineskola
Copy link

benjamineskola commented Nov 13, 2021

I’ve had this issue too (gorm.io/driver/postgres v1.2.2, gorm.io/gorm v1.22.2, Postgres server v14.1) and found that overriding the type of the primary key works as a workaround:

type Something struct {
    ID                uint `gorm:"type:integer”`
    …
}

edit: that’s not entirely right, as it’ll need AUTO_INCREMENT or something set as well.

@jpmeijers
Copy link

Also being affected here after upgrading from jinzhu/gorm to gorm/gorm. Tables in the database were created with the earlier version, now the new version's migration is trying to update them, but fails with this error message:
Unable autoMigrateDB - ERROR: type "bigserial" does not exist (SQLSTATE 42704)

This was referenced Feb 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:with reproduction steps with reproduction steps
Projects
None yet
Development

No branches or pull requests

6 participants