How to add foreign key in sequelize cockroachdb
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 25/100
- Issue type
- Bug
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- javascript, sql
- Domain
- databases
Research direction
Start with the model association shown in the issue and inspect the generated CREATE TABLE statement, especially the unitId foreign key and its ON DELETE SET NULL action. Compare that SQL with CockroachDB's supported foreign-key behavior and verify that creating the user_managements table succeeds without the reported error.
Written by the indexing model from the issue text.
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"));
- Dominant language
- JavaScript
- Stars
- 54
- Forks
- 18
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from cockroachdb/sequelize-cockroachdb
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
-
Difficulty 1/5 Under an hour Newbie friendliness 45/100
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
cockroachdb/sequelize-cockroachdb#153 · 1 comment ·
All issues in cockroachdb/sequelize-cockroachdb
Similar issues
-
Development server fails with webpack-dev-server 6.1.0Possibly taken @utsxvrai claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
rabbitmq/rabbitmq-website#2733 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 80/100
kentcdodds/kcd-skills#32 ·
-
good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
tech-debt
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
enhancement frontend good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 2 days