当所需的数据库字段在 JSON 中时,如何从模型创建数据库模式?

How to create a database schema from models when database fields required are in JSON?

目前,我在模型中将几个 JSON 字段设置为 "object",但我希望这些字段在数据库中为 JSON。但是,当我自动迁移它时,字段正在 MySQL 中创建为文本?如何解决这个问题?

"education": {
    "type": "object"
},
"technology": {
    "type": "object"
},
"certificationsAndAchievements": {
    "type": "object"
}

您可以在模型上使用 mysql 选项并将 dataType 设置为 JSON。现在,当您迁移它时,这将是列类型

{
  "education": {
    "type": "object",
    "mysql": {
      "dataType":"JSON"
    }
  },
  "technology": {
    "type": "object",
    "mysql": {
      "dataType":"JSON"
    }
  },
  "certificationsAndAchievements": {
    "type": "object",
    "mysql": {
      "dataType":"JSON"
    }
  }
}