无论我告诉它TEXT(2048)还是任何其他长度,Sequelize都会将PSQL设置为VARCHAR(255)

时间:2018-11-02 17:19:25

标签: node.js postgresql sequelize.js

当我遵循有关如何通过sequelize在psql中创建更大的字段的说明时,它在创建表时仍始终按func setupRefreshControl() { guard let refreshContents = Bundle.main.loadNibNamed("RefreshControlView", owner: self, options: nil), let refreshView = refreshContents[0] as? RefreshControlView else { return } refreshView.frame = refreshControl.frame refreshControl.addSubview(refreshView) refreshControl.tintColor = UIColor.clear refreshControl.backgroundColor = UIColor.clear refreshControl.addTarget(self, action: #selector(exampleFunction), for: .valueChanged) } func scrollViewDidScroll(_ scrollView: UIScrollView) { for subview in refreshControl.subviews { if let refreshControlView = subview as? RefreshControlView { refreshControlView.activityIndicatorControl.animationView.setAnimation(named: "lottieJson") refreshControlView.activityIndicatorControl.animationView.loopAnimation = true refreshControlView.activityIndicatorControl.animationView.play() break } else { continue } } } Sequelize Data Types

这是我的续集模型:

VARCHAR(255)

'use strict'; module.exports = (sequelize, DataTypes) => { const Message = sequelize.define( 'Message', { message: { type: DataTypes.STRING(2048), allowNull: false, validate: { notEmpty: true } } }, {} ); Message.associate = function(models) { // associations can be defined here }; return Message; }; 具有相同的结果。

这是它输出的SQL:

DataTypes.TEXT

当我尝试在此字段中插入大字符串(超过255个字符)时,出现以下错误:

CREATE TABLE IF NOT EXISTS "Messages" ("id" SERIAL , "message" VARCHAR(255) NOT NULL, "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL, "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL, PRIMARY KEY ("id"));

我已经在该项目上尝试了以下github问题,但它们似乎对我不起作用。 Relevant github issues.

谢谢您的帮助。

规格:

psql(PostgreSQL)error: value too long for type character varying(255)

节点10.5

v10.4.0

1 个答案:

答案 0 :(得分:1)

当我在模型中更改此数据类型时,我犯了一个错误。我忘记对迁移文件进行相同的更改,这是关键。我很高兴就这么简单。

tl; dr

确保迁移的数据类型与模型相同。