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)
更新了数据库模式以添加约束,但模型文件没有.有没有办法在进行迁移时自动更新模型文件?
我正在努力使用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)