Skip to content
New issue

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

UUID primary key for MSSQL #78

Closed
deksden opened this issue May 19, 2016 · 5 comments
Closed

UUID primary key for MSSQL #78

deksden opened this issue May 19, 2016 · 5 comments

Comments

@deksden
Copy link
Contributor

deksden commented May 19, 2016

After importing some MS SQL (2008R2) table i have following field definition in my model:

ID: {
     type: 'UNIQUEIDENTIFIER',
     allowNull: false,
     defaultValue: '(newid())',
     primaryKey: true
 }, 

Actually, IMHO, it should be like this:

ID: {
     type: DataTypes.UUIDV4,
     allowNull: false,
     primaryKey: true
 }, 

P.S. .UUIDV4 makes this field as uuid-type and auto-generate new value for it

@deksden
Copy link
Contributor Author

deksden commented May 19, 2016

Here is PR for this feature: #79

@durango durango closed this as completed May 19, 2016
@leolorenzoluis
Copy link

leolorenzoluis commented Mar 16, 2018

@deksden Producing DataTypes.UUIDV4 breaks SQL Server. Getting an error that column data type UUIDv4 is not found. Changing the DataType to UUID fixes it. Could you double check?

@deksden
Copy link
Contributor Author

deksden commented Mar 19, 2018

Any code/sample? What SQL Server version?

As for time of that issue 2 yrs ago all was fine with tested SQL server versions

@alex-thompson
Copy link

For anyone else who stumbles across this today, you can keep UNIQUEIDENTIFIER (versus CHAR with DataTypes.UUID), by doing:

id: {
  type: 'UNIQUEIDENTIFIER',
  defaultValue: DataTypes.UUIDV4,
  primaryKey: true
},

Just keep the defaultValue as DataTypes.UUIDV4 versus the literal newid() to avoid breaking the model's associations.

@josuerodcat90
Copy link

josuerodcat90 commented Jun 5, 2022

For anyone else who stumbles across this today, you can keep UNIQUEIDENTIFIER (versus CHAR with DataTypes.UUID), by doing:

id: {
  type: 'UNIQUEIDENTIFIER',
  defaultValue: DataTypes.UUIDV4,
  primaryKey: true
},

Just keep the defaultValue as DataTypes.UUIDV4 versus the literal newid() to avoid breaking the model's associations.

Thanks a lot!!!, this still working if any else stuck with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants