generated always as not work on MySQL.
Explanation
type User struct {
ID string //`gorm:"default:uuid_generate_v3()"` // db func
FirstName string
LastName string
Age uint8
FullName string `gorm:"->;type:GENERATED ALWAYS AS (CONCAT(FirstName,' ',LastName));default:xyz;"`
}
func init() {
configure.Connect() // connect the db
db = configure.GetDB()
db.AutoMigrate(&User{})
}
Error
Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'GENERATED ALWAYS AS (CONCAT(FirstName,' ',LastName)) DEFAULT 'xyz',PRIMARY KEY (' at line 1
but it works perfectly in SQL cmd.
CREATE TABLE contacts (
id INT AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(50) NOT NULL,
last_name VARCHAR(50) NOT NULL,
fullname varchar(101) GENERATED ALWAYS AS (CONCAT(first_name,' ',last_name)),
email VARCHAR(100) NOT NULL
);
version
gorm.io/driver/mysql v1.3.6 gorm.io/gorm v1.23.8 MySQL- 8.0.30
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 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.io ✨ Search Before Asking ✨