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

1.2.7 breaks migrations when updating 1.2.5 #6888

Open
ChristianSch opened this issue Mar 10, 2024 · 28 comments
Open

1.2.7 breaks migrations when updating 1.2.5 #6888

ChristianSch opened this issue Mar 10, 2024 · 28 comments
Assignees
Labels

Comments

@ChristianSch
Copy link

ChristianSch commented Mar 10, 2024

Playground link doesn't make any sense, as I'd need to use multiple versions at once.

Say you have the following model:

type User struct {
	BaseModel

	// The user's email address
	Email                    string        `gorm:"not null;uniqueIndex:idx_user_email" json:"email"`
}

Migrating with:

tx.AutoMigrate(&domain.User{})

Causes:

2024/03/10 22:09:04  ERROR: constraint "uni_users_email" of relation "users" does not exist (SQLSTATE 42704)
[0.697ms] [rows:0] ALTER TABLE "users" DROP CONSTRAINT "uni_users_email"

I'd appreciate, if releases would be properly tested beforehand. I'll be pinning 1.2.5 for now.

link for not being marked as stale: https://github.com/go-gorm/playground/issues/0

@github-actions github-actions bot added the type:missing reproduction steps missing reproduction steps label Mar 10, 2024
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 30 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

@ChristianSch
Copy link
Author

v1.25.7-0.20240204074919-46816ad31dde works

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 30 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

@klipach
Copy link

klipach commented Apr 2, 2024

Have the same issue while using v1.25.9 and PostgreSQL. Downgrading to v1.25.5 resolves the issue.

Copy link

github-actions bot commented Apr 2, 2024

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 30 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

@zetaab
Copy link

zetaab commented Apr 9, 2024

we are also seeing this

2024/04/09 05:52:14  pq: constraint "uni_image_statistics_image_id" of relation "image_statistics" does not exist
[0.955ms] [rows:0] ALTER TABLE "image_statistics" DROP CONSTRAINT "uni_image_statistics_image_id"

"error":"pq: constraint \"uni_image_statistics_image_id\" of relation \"image_statistics\" does not exist"

using gorm 1.25.9 and gorm postgres 1.5.7

in our case the model is

type ImageStatistics struct {
	Model                      `json:"-"`
	ImageID                    string         `json:"image_id" gorm:"index:idx_image_id,unique"`
...
}

Copy link

github-actions bot commented Apr 9, 2024

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 30 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

@UninspiredNickname
Copy link

UninspiredNickname commented Apr 10, 2024

I can confirm that - this error happens because in https://github.com/go-gorm/gorm/blob/v1.25.9/migrator/migrator.go#L569 field.Unique returns false when UniqueIndex is used on the models
Simply swapping it to unique;index fixed the problem for me, but field.Unique should be set to true if uniqueIndex is used

@varfrog
Copy link

varfrog commented Apr 12, 2024

I wish this library:

  1. used proper versioning - semver 2.0.0 or go's /vX for breaking changes
  2. had a changelog
  3. test the changes
    big asks fsho... I don't expect any of these to be implemented though. Who versions their libraries anyways... changelog? c'mon...

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 30 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

@PaulSonOfLars
Copy link

PaulSonOfLars commented Apr 20, 2024

+1 on this issue. Also noticed this upon upgrading from 1.25.5 to 1.25.9.

This may be helpful for debugging the root cause -
I noticed that creating tables on 1.25.5 and 1.25.9 results in different table metadata, which is likely related.
Looking at the \d+ output of a table:

  • 1.25.5 creates an idx_<table>_<column> index, as a UNIQUE CONSTRAINT.
  • 1.25.9 creates an idx_<column> index, but only as UNIQUE; not as a constraint.

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 30 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

@ChristianSch
Copy link
Author

Not stale. Doesn't look fixed to me. @jinzhu

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 30 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

@PaulSonOfLars
Copy link

If all it wants is a playground link... Will this work?
https://github.com/go-gorm/playground/issues/0

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 30 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

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 30 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

@ChristianSch
Copy link
Author

Lol this bot is stupid. I added the playground link to the first message ...

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 30 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

@varfrog
Copy link

varfrog commented Apr 24, 2024

Lol this bot is stupid. I added the playground link to the first message ...

What it needs is a link to a pull request in the playground repo. See example how it is here: #6963 - it links to a playground PR where the PR code is a reproducer for the bug

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 30 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

@ChristianSch
Copy link
Author

@varfrog that ticket is marked as stale as well. I don't understand how and why I'd even want to open a PR to anywhere for this topic.

As I'm migrating off of this library, I'll also unsubscribe to this PR. Gorm is not something I'm interested in using anymore.

@klipach
Copy link

klipach commented Apr 24, 2024

@ChristianSch do you know some good alternatives? I'm also planning to migrate to some other tool

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 30 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

@ChristianSch
Copy link
Author

@klipach pgx + scany is what I'm using

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 30 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

@Sophie1142
Copy link

I am also encountering this issue after upgrading from v1.25.5 to v1.25.9. The (abbreviated) definition of my model is:

type Service struct {
	gorm.Model
	Name string      `json:"name"`
	Nickname string  `gorm:"default:NULL;uniqueIndex;check:((nickname IS NOT NULL AND NOT nickname = '' AND nickname ~ '^[a-z0-9_-]+$') OR quick_quote_config_id IS NULL)"`
	ConfigID *uint   `json:"-" gorm:"default:null;check:chk_services_config,(config_id IS NOT NULL OR nickname IS NULL)"`
	Config   *Config `json:"-"``
}

Pinning to v1.25.5 solved my issue.

Copy link

github-actions bot commented May 1, 2024

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 30 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants