8000 AutoMigrate a struct with DEFAULT:0 tag always alert table · Issue #4198 · go-gorm/gorm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
AutoMigrate a struct with DEFAULT:0 tag always alert table #4198
Closed
@jelech

Description

@jelech

Your Question

When I use AutoMigrate a struct with DEFAULT:0 tag, it will always ALTER TABLE when I restart the program.

type TestTable struct {
	ID     uint
        Name string `gorm:"type:varchar(20);NOT NULL;DEFAULT:''"`
	UserID uint `gorm:"type:int;NOT NULL;DEFAULT:0"`
	Status uint `gorm:"type:tinyint;NOT NULL;DEFAULT:0"`
}

It will log this

***/vendor/gorm.io/driver/mysql/migrator.go:83
[140.971ms] [rows:0] ALTER TABLE `test_tables` MODIFY COLUMN `user_id` bigint NOT NULL DEFAULT 0
[174.141ms] [rows:0] ALTER TABLE `test_tables` MODIFY COLUMN `status` tinyint NOT NULL DEFAULT 0

But it is in right state when I see the mysql table. And the 'Name' field DEFAULT:'', it wont ALTER table.

Did I use it wrong?

GORM.version: v1.20.5
GORM.driver.mysql.version: v1.0.3
GORM.datatypes.version: v1.0.0
mysql.version: 8.0.14

The document you expected this should be explained

Not ALTER TABLE when restart program

Expected answer

Is that a BUG?

How do I use it?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0