-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
queryInterface.createTable() does not work with ARRAY(ENUM) with defaultValue #11285
Comments
. (To watch to be notified the solve!) |
I experimented the same problem today. Any progress on this issue? |
@jetaimefrc You can subscribe by clicking the button @jeremyputeaux No progress that I know of |
'use strict'; module.exports = { down: async (queryInterface, Sequelize) => { You can use raw query for array of enum type. It will work. |
Here is a workaround I found, if that helps anyone await queryInterface.sequelize.transaction(async (t) => {
const rightsEnum = [
"view",
"edit",
"coordinate",
"coordinateDepartment",
"approve",
"assign",
"viewDraft",
];
await queryInterface.sequelize.query(
`DROP TYPE IF EXISTS "enum_Faculties_facultyOpopRights"`,
{ transaction: t }
);
await queryInterface.createTable(
"UserAisFaculties",
{
<<fields>>
facultyOpopRights: {
allowNull: false,
defaultValue: [],
type: Sequelize.ARRAY(Sequelize.ENUM(...rightsEnum)),
fieldName: "facultyOpopRights",
Model: {
getTableName() {
return "UserAisFaculties";
},
},
},
},
{ transaction: t }
);
}); |
This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂 |
If anyone is still looking for a solution to this. I encountered it and this is how I went about solving it. Environment
SOLUTION migration
model
Post Notes
And when you use Postico to check the table Test's structure it will have the following details:-
I hope this helps. |
For anyone still struggling with this, somewhere before the version 6.35.0 The following seems to work: roles: {
type: Sequelize.ARRAY(Sequelize.ENUM({ values: ['confirmer'] })),
allowNull: false,
defaultValue: [],
field: 'roles', // Same as attribute name
Model: {
getTableName() {
return 'DepartmentUsers'; // Table name
},
},
}, |
Works with the defaultValue
|
What are you doing?
In postgres:
To Reproduce: Just run the snippet above, no models or other setup needed
2. See error:
TypeError: Cannot read property 'getTableName' of undefined
What do you expect to happen?
It should work
What is actually happening?
TypeError: Cannot read property 'getTableName' of undefined
Thrown at line:
sequelize/lib/dialects/postgres/data-types.js
Line 481 in 748f690
Environment
Dialect:
Tested with latest release:
Extra info
If the
defaultValue
is removed, it works:The text was updated successfully, but these errors were encountered: