2015-11-12 55 views
1

我试图将我的主键的数据类型更改为sequelize中的字符串,并且在尝试使用upsert创建时出现以下错误。错误:列“id”中的空值违反了后续化中的非空约束

error: SequelizeDatabaseError: null value in column "id" violates not-null constraint 

这里是代码:

id: { 
     type: DataTypes.STRING, 
     primaryKey: true, 
     allowNull: true, 
     autoIncrement: false, 
     field: "id" 
    } 

如何使这项工作? 在此先感谢。

回答

2

对于the documentation

Technically, a primary key constraint is simply a combination of a unique constraint and a not-null constraint.

不能创建空的主键。

... 
    allowNull: false, 
    ... 
+0

你是说我不能改变主键的数据类型? –

+1

您可以更改主键的类型,但它总是**不为空**。 – klin

+0

如何将其更改为字符串类型? –

相关问题