question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Primary key type UUID and default value UUIDV1 results in ER_TRUNCATED_WRONG_VALUE_FOR_FIELD

See original GitHub issue

What you are doing?

I am trying to define a table with a primary key. I have tried the following code below with both Sequelize.UUIDV1 and Sequelize.UUIDV4.

const Sequelize = require('sequelize')
let sequelize = new Sequelize(env.mysqlConn, {})
let Foo = seq.define('Foo', { 
      LCID: { 
        type: Sequelize.UUID,
        primaryKey: true,
        defaultValue: Sequelize.UUIDV1
    },
    // more properties below
}, {})

What do you expect to happen?

I wanted Foo to have a column LCID that is a primary key as described in the datatypes documentation

sequelize.define('model', {
  uuid: {
    type: DataTypes.UUID,
    defaultValue: DataTypes.UUIDV1,
    primaryKey: true
  }
})

What is actually happening?

Unhandled rejection SequelizeDatabaseError: ER_TRUNCATED_WRONG_VALUE_FOR_FIELD: Incorrect integer value: 'bf595154-903a-49f9-b324-91d22bf8e777' for column 'LCID' at row 1

Dialect: mysql Database version: mysql Ver 14.14 Distrib 5.7.13, for osx10.11 (x86_64) Sequelize version: 3.23.6

Thought I was following the documentation well. Any suggestions?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
sushantdhimancommented, Jul 23, 2016

It works in master and v3

SSCCE Test

var M = sequelize.define('model', {
  uuid: {
    type: Sequelize.UUID,
    defaultValue: Sequelize.UUIDV1,
    primaryKey: true
  }
})

sequelize.sync({ force: true})
.then(() => M.create({}))
.then(() => M.findAll())
.then(console.log)
.catch(console.error)

Output

[ { uuid: '7cddd200-5095-11e6-845b-1970bb45e00c',
    createdAt: 2016-07-23T05:22:45.666Z,
    updatedAt: 2016-07-23T05:22:45.666Z } ]

But I haven’t started using the MySQL 5.7 yet, May be that is the issue. Travis also only test against 5.6. Can you please post the SQL queries generated

0reactions
sushantdhimancommented, Jul 29, 2016

@SkamDart Thanks, but it seems we really have some issues with MySQL 5.7, We are tracking them here #6345

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sequelize UUID with mySQL: Unable to set default value
By adding defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'), to your createdAt and updatedAt in your migration file defaults the value to ...
Read more >
Migrate Primary Keys to UUIDs - Sequelize/Node
This step meant to go into each model and update each primary key and foreign ... UUID, - autoIncrement: true, + defaultValue: Sequelize....
Read more >
Default value for UUID column in Postgres
Defined by specification as a Version 3 UUID, namespace-based UUID. Based on randomly-generated data for 121-122 of the 128 bits. Six or seven ......
Read more >
Sequelize - using UUID for primary key column in your table ...
Sequelize provides UUIDV1 and UUIDV4 as the default value for UUID type columns that you can use when defining the model.
Read more >
MySQL & UUIDs - lefred blog
Additionally, if we keep the VARCHCAR datatype for our uuid, the primary key could take 146 bytes per row (some utf8 characters can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found