Search code examples
gogo-gorm

Go GORM creates tables but not columns


I am trying to use a go script to setup my database with some tables. The ORM I am using is GORM.

Here is the simplest setup I am using to achieve the task:

package main

import (
    "myapp/internal/database"
)

type Atable struct {
    acolumn bool
}

func main() {
    db := database.GetConnection()

    db.AutoMigrate(&Atable{})
    db.Create(Atable{
        acolumn: false,
    })
}

What this script does is creating the table but it is an empty table without any column.

What should I do in order to let GORM create the columns too?

If I add gorm.Model in the model declaration, only the 4 columns of the model are created (ID, CreatedAt, UpdatedAt, DeletedAt).


Solution

  • Try capitalizing the first letter. like

    type Atable struct {
        Acolumn bool
    }