I'm trying to have a model in sequelize generate a unique ID using DataTypes.UUID
. This throws an error when I serve up my application
ReferenceError: DataTypes is not defined
Here's my code
var Sequelize = require('sequelize');
var sequelize = new Sequelize('uppersphere', '****', '***', {
logging: false
});
...
var Peak = sequelize.define('peak', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV1,
primaryKey: true
},
Here's the documentation
sequelize.define('model', {
uuid: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV1,
primaryKey: true
}
})
The obvious answer is that it's not my code, but there's some require()
that I need. However, I don't see any documentation on what to require to get DataTypes.
The Data Types can be accessed via the Sequelize
object:
var Sequelize = require('sequelize');
var Peak = sequelize.define('peak', {
id: {
type: Sequelize.UUID,
defaultValue: Sequelize.UUIDV1,
primaryKey: true
},
DataTypes
is a just a convenience class which you can import directly if needed:
var DataTypes = require('sequelize/lib/data-types');
Also, the model files are imported with DataTypes
as a second argument
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With