I dont why I keep getting this error and I cant trace the constraint that I am violating.
My two tables are Token
and User
and as you can see from the code below, they linked together through userId
TOKEN TABLE
Token.init(
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
userId: {
type: DataTypes.UUID,
},
refreshToken: {
type: DataTypes.TEXT,
},
createdAt: {
type: DataTypes.DATE,
defaultValue: Date.now(),
},
updatedAt: {
type: DataTypes.DATE,
defaultValue: Date.now(),
},
},
{
sequelize,
modelName: 'token',
}
);
USER TABLE
User.init(
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
unique: true,
primaryKey: true,
},
username: {
type: STRING,
allowNull: false,
},
email: {
type: STRING,
allowNull: false,
},
password: {
type: STRING,
allowNull: false,
},
inactive: {
type: BOOLEAN,
defaultValue: true,
},
activationToken: {
type: STRING,
},
passwordResetToken: {
type: STRING,
},
image: {
type: STRING,
},
createdAt: {
type: DataTypes.DATE,
defaultValue: Date.now(),
},
updatedAt: {
type: DataTypes.DATE,
defaultValue: Date.now(),
},
},
{
sequelize,
modelName: 'user',
}
);
RELATIONSHIP
User.hasMany(Token, { foreignKey: 'userId' });
Token.belongsTo(User);