小编Jef*_*del的帖子

Sequelize迁移应该更新模型文件吗?

Sequelize迁移是否应该使您的模型文件与您的数据库保持一致?

我使用sequelize cli来引导一个简单的项目并创建一个模型node_modules/.bin/sequelize model:generate --name User --attributes email:string.我没有问题地迁移了这个.

然后,我创建了以下迁移文件,以向用户电子邮件属性添加notNull约束.

updateEmail迁移

const models = require("../models")

module.exports = {
  up: (queryInterface, Sequelize) => {
      return queryInterface.changeColumn(models.User.tableName, 'email',{
        type: Sequelize.STRING,
        allowNull: false,
      });
    },

  down: (queryInterface, Sequelize) => {
      return queryInterface.changeColumn(models.User.tableName, 'email',{
        type: Sequelize.STRING,
      });
    },
};
Run Code Online (Sandbox Code Playgroud)

更新了数据库模式以添加约束,但模型文件没有.有没有办法在进行迁移时自动更新模型文件?

sequelize.js sequelize-cli

9
推荐指数
1
解决办法
4879
查看次数

Elm:使用elm-decode-pipeline解码嵌套的对象数组

我正在努力使用NoRedInk/elm-decode-pipeline从OpenWeatherMap转换JSON响应.我已经成功解码了JSON中的嵌套对象,但是对于一个对象数组我不能这样做

我已经包含了我目前的代码.它编译但在运行时失败FetchWeather Err BadPayload ...

JSON

{
     "weather":[{"id":804}],
     "main":{"temp":289.5},
}
Run Code Online (Sandbox Code Playgroud)

type alias OpenWeatherResponse =
  { main: MainResult
  , weather: WeatherResult
  }

type alias MainResult =
  { temp: Float }

type alias ConditionResult =
  { code: Int }

decodeOpenWeatherResponse : Decoder OpenWeatherResponse
decodeOpenWeatherResponse =
    decode OpenWeatherResponse
        |> required "main" decodeMain
        |> required "weather" decodeConditions

decodeMain : Decoder MainResult
decodeMain =
    decode MainResult
        |> required "temp" float

decodeConditions : Decoder ConditionResult
decodeConditions =
     decode ConditionResult
        |> required "id" int -- …
Run Code Online (Sandbox Code Playgroud)

json decode elm

3
推荐指数
1
解决办法
866
查看次数

标签 统计

decode ×1

elm ×1

json ×1

sequelize-cli ×1

sequelize.js ×1