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

fix parseDDL bug with escaped quote #89

merged 1 commit into from Apr 24, 2022

fix parseDDL bug with escaped quote #89

merged 1 commit into from Apr 24, 2022


Copy link

@duc-cnzj duc-cnzj commented Apr 14, 2022

  • Do only one thing
  • Non breaking API changes
  • Tested

What did this pull request do?

fix parseDDL bug with escaped quote, (This is probably a p0 level bug)

User Case Description

Data loss occurs when exec AutoMigrate!

reproduces: v1.3.1 v1.23.4

  1. run AutoMigrate, create users table
package main

import (

type User struct {
	ID int `json:"id" gorm:"primaryKey;"`

	FirstName string `json:"first_name" gorm:"size:100;not null;default:''"`
	LastName  string `json:"last_name" gorm:"size:100;not null;default:''"`
	Age       int    `json:"age" gorm:"not null;default:0"`

func main() {
	db, err := gorm.Open(sqlite.Open("/tmp/sqlite.db"), &gorm.Config{})
	if err != nil {
		panic("failed to connect database")

	if err := db.AutoMigrate(&User{}); err != nil {
  1. insert data INSERT INTO "users" ("first_name", "last_name", "age") VALUES ('xiao', 'ming', '18');


  1. run AutoMigrate again, data loss!


@jinzhu jinzhu merged commit 0a99da5 into go-gorm:master Apr 24, 2022
1 check passed
Copy link

@jinzhu jinzhu commented Apr 24, 2022

Oops, sorry for the bug, thank you for your PR.

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

Successfully merging this pull request may close these issues.

None yet

2 participants