Beego ORM Auto-Build table when the field default value does not set the workaround

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

This is how my model was built when I used Beego's ORM to build a table.

Type Test struct {Id      int64name    stringsex     Int64 ' ORM: ' Default (1) ' Age     int64content string ' orm: " Default (') '}



The Content field is set to NULL by default, the Sex field is set to default to 1, then the generated table does not have default, this is not scientific, so I turned over the source code, found that the default is the paragraph is commented, the location of the Github.com/astaxie/beego/orm /cmd_utils.go

155//If fi.initial.String ()! = "" {156//Column + = "DEFAULT" + fi.initial.String () 157//}



The three lines of comment, the decisive open (Brother Test, open no risk, bold to do), Ouke, the time to build the table solved the field default problem

Next, if you already have a table, and then add a field, you will still encounter the case that the field does not have default, we add, or this file, in line 107th

If fi.initial.String ()! = "" {Typ + = "DEFAULT" + fi.initial.String ()}



Add the field to the time of the OU, modify the field of the Beego did not do, hope to be able to the whole


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.