본문 바로가기

카테고리 없음

Sequelize Model Generate Primary Key



Join GitHub today

May 06, 2017 This model is the root model that will allow Sequelize to read all the other models you make. It connects your app to the database by way of the lowercase sequelize instance of the Sequelize constructor, which, for now, reads the connection configuration set in the config file, places it in the db object, and exports that connection along with all of your models to be read by other files in. Aug 17, 2019  You can also just say primaryKey:true on several columns, and sequelize will understand that it's a composite key. At least, it does on top of postgres. At least, it does on top of postgres. (Against sequelize@4.33.4).

GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.

Sign upNew issue

Sequelize

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Labels

Comments

commented Apr 10, 2020

Issue Description

If a non-primary key column is named 'id' in the model, the value of this field would always override the value of the actual primary key in the data returned from Model.create() function

What are you doing?

What do you expect to happen?

The field actualId should return the auto-incrementing integer value.

What is actually happening?

The value of actualId is actually overwritten by the value from the id column.

Environment

  • Sequelize version: 5.X
  • Node.js version: 10.X
  • Operating System: All
  • Dialect: mssql

How does this problem relate to dialects?

  • I think this problem happens only for the following dialect(s): mssql

Would you be willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time but I don't know how to start, I would need guidance.

Found the cause of the bug here:

added the type: bug label Apr 10, 2020
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Sequelize Composite Primary Key

-->

APPLIES TO: SQL Server 2016 and later Azure SQL Database Azure Synapse Analytics (SQL DW) Parallel Data Warehouse

You can define a primary key in SQL Server by using SQL Server Management Studio or Transact-SQL. Creating a primary key automatically creates a corresponding unique clustered index, or a nonclustered index if specified as such.

Before You Begin

Limitations and Restrictions

  • A table can contain only one PRIMARY KEY constraint.

  • All columns defined within a PRIMARY KEY constraint must be defined as NOT NULL. If nullability is not specified, all columns participating in a PRIMARY KEY constraint have their nullability set to NOT NULL.

Security

Permissions

Creating a new table with a primary key requires CREATE TABLE permission in the database and ALTER permission on the schema in which the table is being created.

Creating a primary key in an existing table requires ALTER permission on the table.

Using SQL Server Management Studio

To create a primary key

  1. In Object Explorer, right-click the table to which you want to add a unique constraint, and click Design.
  2. In Table Designer, click the row selector for the database column you want to define as the primary key. If you want to select multiple columns, hold down the CTRL key while you click the row selectors for the other columns.
  3. Right-click the row selector for the column and select Set Primary Key.

Caution

If you want to redefine the primary key, any relationships to the existing primary key must be deleted before the new primary key can be created. A message will warn you that existing relationships will be automatically deleted as part of this process.

A primary key column is identified by a primary key symbol in its row selector.

If a primary key consists of more than one column, duplicate values are allowed in one column, but each combination of values from all the columns in the primary key must be unique.

If you define a compound key, the order of columns in the primary key matches the order of columns as shown in the table. However, you can change the order of columns after the primary key is created. For more information, see Modify Primary Keys.

Using Transact-SQL

To create a primary key in an existing table

The following example creates a primary key on the column TransactionID in the AdventureWorks database.

To create a primary key in a new table

The following example creates a table and defines a primary key on the column TransactionID in the AdventureWorks database.

To create a primary key with clustered index in a new table

The following example creates a table and defines a primary key on the column CustomerID and a clustered index on TransactionID in the AdventureWorks database.

Sequelize Model Generate Primary Key 2017

See Also