cockroachdb / cockroachdb/sequelize-cockroachdb

How to add foreign key in sequelize cockroachdb

Open
#10 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
55
Forks
18
PR merge metrics
No merged PRs in 30d

Description

I have model like
```
let init = function() {
return user_management = connection.define('user_management', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
email_id: {
type: sequelize.STRING,
allowNull: false
},
password: {
type: sequelize.STRING
},
first_name: {
type: sequelize.STRING,
allowNull: false
},
middle_name: {
type: sequelize.STRING,
allowNull: true
},
last_name: {
type: sequelize.STRING,
allowNull: false
},
title: {
type: sequelize.STRING,
allowNull: false
},
company_name: {
type: sequelize.STRING,
allowNull: true
},
organisation_strength: {
type: sequelize.STRING,
allowNull: true
},
industry: {
type: sequelize.STRING,
allowNull: true
},
phone_number: {
type: sequelize.INTEGER,
allowNull: false
},
url: {
type: sequelize.STRING,
allowNull: true
},
personnel_number: {
type: sequelize.INTEGER,
allowNull: true
},
},
// I want to add unit id as foreign key in usermanagement table.
classMethods: {
associate: function(model) {
var usermanagement = model.user_management;
var unit = model.unit;
usermanagement.belongsTo(unit)
},
})
}
module.exports = init
```

I am getting error while trying to create table
Unhandled rejection SequelizeDatabaseError: unimplemented at or near "null"
**CREATE TABLE IF NOT EXISTS "user_managements" ("id" SERIAL , "email_id" VARCHAR(255) NOT NULL, "password" VARCHAR(255), "first_name" VARCHAR(255) NOT NULL, "middle_name" VARCHAR(255), "last_name" VARCHAR(255) NOT NULL, "title" VARCHAR(255) NOT NULL, "company_name" VARCHAR(255), "organisation_strength" VARCHAR(255), "industry" VARCHAR(255), "phone_number" INTEGER NOT NULL, "url" VARCHAR(255), "personnel_number" INTEGER, "user_role" VARCHAR(255) NOT NULL, "salt" VARCHAR(255), "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL, "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL, "unitId" INTEGER REFERENCES "units" ("id") ON DELETE SET NULL ON UPDATE CASCADE, PRIMARY KEY ("id"));**

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.