Hi,
I'm wondering if it's possible to specify charset and collation for table creation?
I searched existing issues and found one answer that allows to set it at the column level
sql:"type:VARCHAR(5) CHARACTER SET utf8 COLLATE utf8_general_ci"
What is I'd like to specify the entire table charset/collation?
Thanks
Comment From: github-actions[bot]
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.io ✨ Search Before Asking ✨
Comment From: haozhou
Your Question
Is it possible to specify charset and collation for table creation?
The document you expected this should be explained
Consdier following struct
type Contract struct {
gorm.Model
code int64
rate float64
}
By default db.AutoMigrate(&Contract{}) creates the database table using default charset and collation (Mysql)
Expected answer
Expect a way to specify charset and collation at the struct level so that the corresponding table schema will be created using specified charset and collation
Comment From: github-actions[bot]
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.io ✨ Search Before Asking ✨
Comment From: jinzhu
db.Set("gorm:table_options", xxx)
Comment From: NiranjanSwabhav
db = db.Set("gorm:table_options", "ENGINE=InnoDB CHARSET=utf8 COLLATE=utf8_bin")
Note: new db has to be stored as it is cloned by SET()