Seeding ARRAY(ENUM)
See original GitHub issueIssue Description
I am trying to seed an ARRAY(ENUM), but I have not been able to figure out how to do so. I also haven’t been able to find any other issue/documentation that showed how to do this.
I keep getting this error:
ERROR: column "roles" is of type "enum_Users_roles"[] but expression is of type text[]
This is my migration script:
return queryInterface.createTable('Users', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
email: {
type: Sequelize.STRING,
allowNull: false
},
password: {
type: Sequelize.STRING,
allowNull: false
},
roles: {
type: Sequelize.ARRAY(Sequelize.ENUM({
values: ['user', 'setter', 'admin']
})),
allowNull: false
},
public_id: {
type: Sequelize.UUID,
defaultValue: Sequelize.UUIDV4,
allowNull: false
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
})
And here is my seed file:
'use strict';
const faker = require('faker');
module.exports = {
up: async (queryInterface, Sequelize) => {
return queryInterface.bulkInsert('Users', [
{
email: faker.internet.email(),
roles: ['user'],
password: "hash",
public_id: faker.random.uuid(),
created_at: new Date(),
updated_at: new Date()
}
]);
},
down: (queryInterface, Sequelize) => {
return queryInterface.bulkDelete('Users', null, {});
}
};
StackOverflow / Slack attempts
I asked on StackOverflow, but I have not gotten any response (it has only been a day) https://stackoverflow.com/questions/58326145/sequelize-seeding-arrayenum
Issue Template Checklist
Is this issue dialect-specific?
- No. This issue is relevant to Sequelize as a whole.
- Yes. This issue only applies to the following dialect(s): XXX, YYY, ZZZ
- I don’t know.
Would you be willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time and I know how to start.
- Yes, I have the time but I don’t know how to start, I would need guidance.
- No, I don’t have the time, although I believe I could do it if I had the time…
- No, I don’t have the time and I wouldn’t even know how to start.
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (4 by maintainers)
Top Results From Across the Web
Sequelize Seeding ARRAY(ENUM) - Stack Overflow
I cannot seem to figure out how to seed ARRAY(ENUM) using Sequelize. When I am registering a user via my app, I can...
Read more >How to seed schema containing enums - Questions - Prisma 1
Howdy! How do we seed a schema containing enums? The above throws the error: Error: Variable '$data' expected value of type 'PlaceCreateInput!'
Read more >[Solved]-Sequelize Seeding ARRAY(ENUM)-node.js
Coding example for the question Sequelize Seeding ARRAY(ENUM)-node.js. ... Obviously you'll want to change the array values and enum values.
Read more >Extension Method to Seed Enum Values into Database Table
When an enum is persisted in a database table, it is better if the Code First entity doesn't use a (SQL Server) IDENTITY...
Read more >How to Use Enums in Rails | Saeloun Blog
Since we have used arrays for declaring enums, draft will be mapped to 0 in the database, published will be mapped to 1,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@papb sorry. Didn’t mean to close it on you. The stackoverflow question got a some views and a few thumbs up, so I guess I am not the only one trying to figure it out. Probably a good call to add it to docs. Thanks
You can use this code